Working with files with international characters in Linux/Unix
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bryan_rall
Posted On:   Wednesday, August 4, 2004 09:37 AM

I am attempting to use the java.io.File class to access files on a *nix system that have international characters and I am getting some strange results. I have tested this test case on Red Hat Linux 3.2 JSE 1.4.2_04 and Solaris 9 1.4.2. Here is the setup: I have a directory with two files f1.txt and arrancó.txt ls temp arranc?.txt f1.txt I’m running this test program on this directory to simply list the contents of the directory and check each file that is returned to see if it exits: File f = new File(argv[0]); File ls[] = f.listFiles(); String line; for (int i = 0; i < ls.length; i++) { File l = ls[i]; System.out.println("File:"+l   More>>

I am attempting to use the java.io.File class to access files on a *nix system that have international characters and I am getting some strange results. I have tested this test case on Red Hat Linux 3.2 JSE 1.4.2_04 and Solaris 9 1.4.2. Here is the setup: I have a directory with two files f1.txt and arrancó.txt

			
ls temp
arranc?.txt f1.txt


I’m running this test program on this directory to simply list the contents of the directory and check each file that is returned to see if it exits:
			
File f = new File(argv[0]);
File ls[] = f.listFiles();
String line;
for (int i = 0; i < ls.length; i++) {
File l = ls[i];
System.out.println("File:"+l.getPath()+" "+l.exists());
}

Here is the here is the output of the program:
			
File:temp/f1.txt true
File:temp/arranc?.txt false


As a result I can’t seem to do anything with that file arrancó.txt. All subsequent IO operations fail. Any idea how to get around this problem?


Thanks,


--BRYAN RALL

   <<Less

Re: Working with files with international characters in Linux/Unix

Posted By:   Stephen_Ostermiller  
Posted On:   Wednesday, August 4, 2004 10:46 AM

Works for me in redhat 9:



$ ls
arrancó.txt Test.class Test.java
$ cat Test.java
import java.io.File;

public class Test {
public static void main(String[] argv){
File f = new File(argv[0]);
File ls[] = f.listFiles();
String line;
for (int i = 0; i < ls.length; i++) {
File l = ls[i];
System.out.println("File:"+l.getPath()+" "+l.exists());
}
}
}
$ java Test .
File:./arrancó.txt true
File:./Test.class true
File:./Test.java true


Redhat 3.2 is very old. You should upgrade. I'm not sure about Solaris.
About | Sitemap | Contact