Results 1 to 6 of 6

Thread: Platform independent path name

  1. #1
    Join Date
    Oct 2009
    Posts
    82

    Platform independent path name

    Hello,
    I am working on an application that we want to be portable (standard me tell you it's Java ) Different OSes (especially Windows, Linux and Mac). Yet, I worry a little, because the execution of this snippet:
    Code:
    if (!new File(filename).exists()){
      System.out.System.out.println("The file \"" + Filename + "\" does not exist! ");
      return;
    }
    Indeed, personally I'm on Windows and if I run it with any box for the file name (foo.txt, foo.txt, etc. ...), it goes and everything goes well. And if a colleague is running on Mac, he must put exactly the right breaks from the existing file, if the method exists returns false.
    Hence my questions:
    - So the OS that causes this difference?
    - How to have the same result on different OS? (completely insensitive or completely sensitive)?

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Platform independent path name

    Hello,
    That's the OS that is sensitive or not case sensitive. In Java, we can apply the method. ToUpperCase () for that seizure is converted to uppercase but if the file names themselves are both lowercase and uppercase, I see no other solution than to read entire directory and compare it with. toUpperCase () for each file.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: Platform independent path name

    Hello,
    I had done a program related to this topic, just check it out
    Code:
    class mfl extends File {
    	Public mfl(String file){
    		great(file);
    	}
    	
    	//[...] Another constructor 
    	
    	Public boolean exists(){
    		if (great.exists()) / / This code was tested
    			return true;	/ / With this part with commentary
    		
    		File drc = new File(getParent());
    String all [] dr =.list();		
    		for (String one: all){ 
    			if (one.equalsIgnoreCase(getName()));
    				return true;
    		}
    		return false;
    	}
    	
    	Public static void hand(String [] arg){
    				
    		mfl mf = new mfl("c" + File.separator + "IO.SYS"); / / Windows only 
    		p.rintln("file exist"+ mf.exists());
    		
    	}
    }

  4. #4
    Join Date
    Oct 2009
    Posts
    82

    Re: Platform independent path name

    Hello,
    Here is my code, I have being trying it for a long time now, but it is still not working, just go thorough my code.
    Code:
    Public class mf extends File {
     
    	Public mf(String file){
    		great(file);
    	}
     
    	Public boolean exists(){
    		if (great.exists())
    			return true;
     
    		/ / For OS case sensitive
    		File dir = new File(getParent());
    String all [] Dir =.list();		
    		for (String one: all){ 
    			if (one.equalsIgnoreCase(getName()))
    				return true;
    		}
    		return false;
    	}
    
    	Public static void hand(String[] args) throws IOException {
    		/ / TODO Auto-generated method stub
    		while (1==1){
    			System.out.System.out.println("Name of file to test?");
    InputStreamReader rd =new InputStreamReader(System.in);
    BufferedReader in =new BufferedReader(rd);
    mf mf = new mf(in.readLine());
    System.out.System.out.println("The file exists" + Mf.exists());
    		}
    	}
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Platform independent path name

    Hello,
    The JVM does this, it adapts the conventions of systems. If on a Windows case does not matter, this may be problematic to make search case-insensitive on a Unix system, because "file" and "file" are two different files (which open so when the User input "FILE"?). In short it would be simpler and more "portable" by not making special treatment to simulate the case-insensitive.

  6. #6
    Join Date
    Oct 2009
    Posts
    82

    Re: Platform independent path name

    Hello,
    I throw a look at the function File (). Rev () for the path. Otherwise, actually, my problem was that the research file for a certain flexibility to the user. The idea is to locate the correct file with "equalsIgnoreCase" whether he exists. Then use the actual file name (real case) for such work with the following code:
    Code:
    if (one.equalsIgnoreCase(getName())){
    	renm = one;
    	return true;
    }

Similar Threads

  1. Replies: 5
    Last Post: 07-04-2011, 07:26 PM
  2. Is JavaFX platform independent?
    By Messenger in forum Software Development
    Replies: 4
    Last Post: 23-07-2010, 10:26 AM
  3. Replies: 0
    Last Post: 23-03-2009, 11:32 PM
  4. Wikipedia asks for help to stay independent
    By Wajeeh in forum Windows Software
    Replies: 4
    Last Post: 02-01-2009, 03:18 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,751,748,445.07062 seconds with 16 queries