[Java] 纯文本查看 复制代码
public class Test02 {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("HelloWorld.txt");
StringBuilder sb = new StringBuilder();
int read = -1;
while ((read = fr.read()) != -1) {
sb.append((char)read);
}
fr.close();
String ret = sb.toString();
System.out.println(ret);
}
}
[Java] 纯文本查看 复制代码
public class Test03 {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("HelloWorld2.txt");
StringBuilder sb = new StringBuilder();
char[] arr = new char[1024];
int count = -1;
while ((count = fr.read(arr)) != -1) {
String str = new String(arr, 0, count);
sb.append(str);
}
fr.close();
String ret = sb.toString();
System.out.println(ret);
}
}
[Java] 纯文本查看 复制代码
public class Test04 {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("HelloWorld2.txt");
BufferedReader br = new BufferedReader(fr);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\r\n");
}
br.close();
System.out.println(sb.toString());
}
}