第一种方法
private static void ReadFile(String filePath) {
try {
StringBuilder stringBuilder = new StringBuilder(50);
FileReader fileReader = new FileReader(filePath);
int i;
while ( (i = fileReader.read()) != -1) {
stringBuilder.append((char)i);
}
System.out.println(stringBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
第二种方法
private static void ReadFile(String filePath) {
try {
StringBuilder stringBuilder = new StringBuilder(50);
FileReader fileReader = new FileReader(filePath);
char[] bytes = new char[1024];
while (fileReader.read(bytes) != -1) {
stringBuilder.append(bytes);
}
System.out.println(stringBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
}
}