there I'm making this app to change subtitle files. when I was testing it I faced a strange problem, when I was testing it on non-english (persian for instance) the program wouldn't read the file. this is how I read subtitles in my program:
Scanner sub = null;
try {
sub = new Scanner(new File(address));
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
while(sub.hasNext()){
String sentence = sub.nextLine();
//some magical stuff here :)
}
where address is a String keeping place of .srt file.
what should I do so the program reads the file?
Select a different encoding when creating the
Scanner
.Something along the lines of this might work:
This will change the scanner to read the file using a UTF-16 encoding.
You can read up more on encodings here.
This is the constructor I could find from the java doc. Try to find the encoding for your input file and use this constructor. I think this should work.