i think the problem is that java reads / writes in the computers encoding. so, if the file was made on a mac and is read on win java assumes it's encoded for/by win. unicode won't help you there as java does not attempt to detect the encoding (which would slow down every read/write process and detection might not even be possible in any case). i think internally java already uses unicode.
anyway here's what might work (more or less directly copied from
processings source):
Code:
void setup (){
String[] mytest = loadStrings("myMacFile.txt", "ISO-8859-1");
}
void draw (){
}
static public String[] loadStrings(File file, String _enc) {
InputStream is = openStream(file);
if (is != null) return loadStrings(is, _enc);
return null;
}
public String[] loadStrings(String filename, String _enc) {
InputStream is = openStream(filename);
if (is != null) return loadStrings(is,_enc);
System.err.println("The file \"" + filename + "\" " +
"is missing or inaccessible, make sure " +
"the URL is valid or that the file has been " +
"added to your sketch and is readable.");
return null;
}
static public String[] loadStrings(InputStream input, String _enc)
{
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(input, _enc));
String lines[] = new String[100];
int lineCount = 0;
String line = null;
while ((line = reader.readLine()) != null) {
if (lineCount == lines.length) {
String temp[] = new String[lineCount << 1];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
}
lines[lineCount++] = line;
}
reader.close();
if (lineCount == lines.length) {
return lines;
}
// resize array to appropriate amount for these lines
String output[] = new String[lineCount];
System.arraycopy(lines, 0, output, 0, lineCount);
return output;
}
catch (IOException e) {
e.printStackTrace();
//throw new RuntimeException("Error inside loadStrings()");
}
return null;
}
all you should have to do is supply the correct encoding of the .txt file to the encoding-savvy loadStrings() ..
/F