为什么我不能在一行中加入 FileReader 和 System.out.println?
Why can't I join FileReader and System.out.println in one line?
谁能帮帮我,为什么我不能在一行中加入 FileReader 和 System.out.println。
File cf = new File("D:\jv\test.txt");
FileReader cfr = new FileReader(cf);
char[] cc = new char[4096];
cfr.read(cc); // join line 1
System.out.println(cc); // join line 2
// Jointing line 1 and 2 gives the file lenth only, not the content.
// System.out.println(cfr.read(cc));*
谢谢!
我认为您混淆了 cfr.read
和 System.out.println
的作用。
FileReader
将为您提供API执行文件读取任务。
System.out.println
将允许您“打印一行”到“System.out”频道(控制台)。
System.out.println(cfr.read(cc));
此行不会打印出字符串,因为方法 cfr.read()
不会 return 字符串。它 return 是 int
见:https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html#read-char:A-
谁能帮帮我,为什么我不能在一行中加入 FileReader 和 System.out.println。
File cf = new File("D:\jv\test.txt");
FileReader cfr = new FileReader(cf);
char[] cc = new char[4096];
cfr.read(cc); // join line 1
System.out.println(cc); // join line 2
// Jointing line 1 and 2 gives the file lenth only, not the content.
// System.out.println(cfr.read(cc));*
谢谢!
我认为您混淆了 cfr.read
和 System.out.println
的作用。
FileReader
将为您提供API执行文件读取任务。System.out.println
将允许您“打印一行”到“System.out”频道(控制台)。
System.out.println(cfr.read(cc));
此行不会打印出字符串,因为方法 cfr.read()
不会 return 字符串。它 return 是 int
见:https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html#read-char:A-