Reputation: 27
I would like to convert this relative path /home/cce2050/Music/part1/ints10000.dat to its absolute path. Can anybody suggest me the path?
public static String[] split() throws FileNotFoundException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("/home/cce2050/Music/part1/ints10000.dat")));
String line;
String[] aList = new String[10000];
while ((line = reader.readLine()) != null) {
aList = line.split("\\s+");
}
return aList;
}
Upvotes: 0
Views: 981
Reputation: 748
If you're looking to convert a relative path to an absolute path, I would recommend using File.getCanonicalPath()
You can see the docs on it here. Additionally, you can read a little more about relative and absolute path conversions here.
So if you wanted to find the relative path, you could write something like:
String absolutePath = (new File("Your/Relative/Path")).getCanonicalPath()
That being said, let it be known that Unix System absolute file paths are referenced from the /home
directory. The file path you specified may already be absolute
Upvotes: 1
Reputation: 3032
You have a miss a confusion between absolute and relative paths, so I think you are asking about this:
./Music/part1/ints10000.dat
Upvotes: 0
Reputation: 63
I personally think you have a wrong understanding in what is relative/absolute path. Absolute path specifies path from the root / to the file while relative path specifies path from the current directory (position) to the specified file.
The path you have provided is an absolute path already.
Upvotes: 0