My java program converts a text file into a string, but when I save this text file with UT8 format, it adds a weird code to my string. How can I fix it? Is UT8 format incompatible with java or something?
Please clarify, thank you.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
/*
* This program reads a file and converts the content into a string. (String container)
* */
public class ReadFileString {
public static void main(String[] args) {
BufferedReader br = null;
try {
String cr;
String container = ""; //text in file would be converted into a string "container"
br = new BufferedReader(new FileReader("C:\\test.txt"));
while ((cr = br.readLine()) != null) {
container = container + cr + " ";
}
System.out.print(container);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}