Results 1 to 5 of 5

Thread: Managing path under windows and linux

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Managing path under windows and linux

    Hello,
    I am currently developing an application that will run under Windows and Linux. In some functions, I must create / del / edit representations and how it works for both Windows & under linux? One way windows will be of the form c: \ folder \ foo \ etc. then linux will be a path of form / folder / foo / etc. That is I need to manage the paths under windows and linux. Is there an easy way to handle this or should he take a test to check the OS of the user to choose to use the method supprRepWindows or supprRepLinux?

  2. #2
    Join Date
    Nov 2009
    Posts
    333

    Re: Managing path under windows and linux

    Hello,
    The JVM offers you a lot of tools to handle this elegantly, for example see the method below.
    Code:
    System.getProperty("user.dir");
    this will return the current directory. I recommend you to watch the doc on System.getProperty. You also have the File class that offers a number of methods including static separator () which returns you the correct character to use to construct a path.

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Managing path under windows and linux

    Hello,
    I think you do not have to worry about it. You pass by java.io I suppose, that is you are trying to do this by using the java.io ( java input and output) and I guess you are using the methods and classes which below to the java.io. You can express your path like c: / folder/file1.txt, it will work on Windows and Linux. This is the beauty of java , that it is cross platform, so I do not think you really want to worry about the code you are writing, it will run on all operating systems.

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Managing path under windows and linux

    Hello,
    What do you mean? To write a file you're going to do for example:
    Code:
    PrintWriter pw = new PrintWriter(new FileWriter(new File("c: / folder / file.txt"));
    while(...)
    {
       ...
       pw.System.pw.println(...);
       ...
    }
    I doubt that it works under linux. The problem seems even more present when reading the file does not exist in my opinion -> exception.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Managing path under windows and linux

    Hello,
    There are various methods that allow you to deal with almost everything.
    I am suspicious of forms c: / foo / bar because it's just something that shows that it works, and not something that should work. You can work from the system properties such user.dir, and all of the method will File. For a list of roots, used File.listRoots. Progress in rail, use the form new = new File (base, name)Still progressing step by step. To retrieve a parent uses file.getParent (). There are many helpful methods in java.io which make things easy. Hope you will do the code easily.

Similar Threads

  1. Managing folder system in windows server
    By Mercia mAC in forum Networking & Security
    Replies: 5
    Last Post: 28-11-2010, 12:10 AM
  2. Managing filesystem LVM in linux
    By blueprats in forum Guides & Tutorials
    Replies: 4
    Last Post: 28-06-2010, 10:36 AM
  3. How to set Environment Variable Path in Linux
    By GunFighter in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 02:56 PM
  4. Managing, Using & Configuring Fax Console in Windows XP
    By spookshow in forum Guides & Tutorials
    Replies: 2
    Last Post: 26-05-2009, 11:46 AM
  5. Replies: 0
    Last Post: 23-03-2009, 11:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,518,457.13850 seconds with 16 queries