Files


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Files

  1. #1
    Join Date
    Oct 2004
    Posts
    151

    Question 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

    Code:
        "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

  2. #2
    Join Date
    Aug 2004
    Location
    On the net
    Posts
    38
    Hi,

    I have a doubt in your question. What does it mean by making the path compatible to OS?

    My understanding:

    U said that your code is working fine with windows(Also, you can use something like c:/p/kol/pki.txt). Now coming to Unix you need to specify the exact input path like /<dir1>/<dir2>/<filename.txt>

    Good Luck :-)

    Narayana

  3. #3
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    What I usually do (writing code for both windoze, AIX and Linux), is:

    a) use relative paths only, and either use File.separator or always use '/' as a path separator.

    b) leave it up to the user to enter path information (someone on *nix might enter /usr/bin/whatever, and someone on windows might enter c:\Program Files\whatever

    c) Have a method to get which platform you are on, and use a different path based on that information. System.getProperty('os.name') and compare to "Windows" or something - you should find the exact env variable and value yourself, of course, as a good exercise.

    hope that helps.

  4. #4
    Join Date
    Oct 2004
    Posts
    151

    Question

    Hi everyone,

    Doredson can i do this to create a platform independent file

    Code:
       
         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


    Code:
        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

  5. #5
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    C: is a windows-ism, so no.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center