Friday 28 December 2012

Get Portion Of String from File Path in Java

import java.nio.file.*

Path fullPath = new File("/home/ubuntu/Documents/DesktopApplicationProject/JewlleryApplication/Jewellery Data/Ring/widget.jpg").toPath()

Path base = new File("/home/ubuntu/Documents/DesktopApplicationProject/JewlleryApplication").toPath()

String relativePath = base.relativize(fullPath).toString()

In Output you Get :

/Jewellery Data/Ring/widget.jpg.