Files
Hi everyone,
I have a rather silly question but please bear with me for a while. If lets say i have a string which has the contents
"C:\\p\\kol\\pki.txt"
the thing with the above string is that if i use as an argument in a
fileinputstream it will only work on windows platform.
Basically my question is how do i convert the above string to a platform independent form.
I hope someone can help me with this
Thank You
Yours Sincerely
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
well, as it uses a drive letter it will ever only work on Windows...
That's the problem with files, path structures are platform dependent.
The best you can do is to either use relative paths only so you will always look from your installation directory, in which case you can use the system properties to get the path separator (path.separator system property) to figure out whether to use / or \, or else to use a configuration file which contains the filenames and paths. You can make this a file unique to each platform or (this should be possible) detect the platform you're running on and select the single correct entry for that platform from the config file based on that.
As config files can be stored and read using Java classpath entries through ResourceBundle there's no need to know the exact path specifiers for them.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
Hi everyone,
Can i do this to create a platform independent file
String str1 = "C:\\abc\\efg.exe"
File file1 = new File(str1);
String str2 = file1.getCanonicalPath();
//Now i will the instance of str2 for any file streams
OR THIS
String str1 = "C:\\abc\\efg.exe"
File file1 = new File(str1);
String str2 = file1.getAbsolutePath();
//Now i will the instance of str2 for any file streams
Will what i do create a platform independent file?
By the way
Merry Christmas and a Happy New Year to everyone
Thank You
Yours Sincerely
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10