Hi
I was doing some tests as you suggested and here is the outcome (I
still coudlnt resolve it...)
1. Trying to see if the file exists with File.exists() results with
false
2. I verified manually that the file is a file and not a folder
3. I tried both to hardcode the file path inside my java code and to
check if the file exists - resulted in false, and to read the file path
from another file (which also resulted in false)
here are the tests
when i do:
C:\>dir C:\temp\1\עברית
Volume in drive C has no label.
Volume Serial Number is F0C1-B8A2
Directory of C:\temp\1
03/29/2006 17:50 18 עברית
1 File(s) 18 bytes
0 Dir(s) 50,586,972,160 bytes free
C:\>
Code:
public static void main(String[] args) throws Exception {
File file = new File("/temp/1/תומר");
System.out.println(file.exists());
InputStream is = new FileInputStream(file);
}
Result:
false
Exception in thread "main" java.io.FileNotFoundException: \temp\1\????
(The syst
em cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at TDFileUtils.main(TDFileUtils.java:235)
Code:
public static void main(String[] args) throws Exception {
File file = new
File(TDFileUtils.getInstance().fileToString("/temp/1.txt")); // read
the file path from a different file that holds it
System.out.println(file.exists());
InputStream is = new FileInputStream(file);
}
public String fileToString(String filePath) throws
FileNotFoundException, IOException {
return new String(fileToBytes(filePath));
}
/** Returns the contents of the file in a byte array. */
public byte[] fileToBytes(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset))
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file
"+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
public byte[] fileToBytes(String filePath) throws IOException {
return fileToBytes(new File(filePath));
}
Result:
false
Exception in thread "main" java.io.FileNotFoundException:
C:\temp\1\=ß°T· (The
ystem cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at TDFileUtils.main(TDFileUtils.java:238)
And when i'm updating the method fileToString to be:
public String fileToString(String filePath) throws
FileNotFoundException, IOException {
return new String(fileToBytes(filePath),
System.getProperty("file.encoding"));
}
Then the result is:
false
Exception in thread "main" java.io.FileNotFoundException:
C:\temp\1\=ß°T· (The s
ystem cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at TDFileUtils.main(TDFileUtils.java:238)
The content of the file /temp/1.txt is: C:\temp\1\עברית which is a
file that exists... according to the dos
when i do:
C:\>dir C:\temp\1\עברית
Volume in drive C has no label.
Volume Serial Number is F0C1-B8A2
Directory of C:\temp\1
03/29/2006 17:50 18 עברית
1 File(s) 18 bytes
0 Dir(s) 50,586,972,160 bytes free
C:\>