Java Read file
/*string Path = "D:/project/training/src/com/test1/test.txt";
File File = new file (path);
if (!file.exists () | | file.isdirectory ()) {
SYSTEM.OUT.PRINTLN ("error");
}
try {
BufferedReader br = new BufferedReader (new FileReader (file));
String temp = null;
StringBuffer sb = new StringBuffer ();
temp = Br.readline ();
while (temp! = null) {
SYSTEM.OUT.PRINTLN (temp);
temp = Br.readline ();
}
} catch (IOException e) {
SYSTEM.OUT.PRINTLN ("error");
}*/
///?? This is all file, if the file is blank, why do you read a Chinese
String filepathandname = "D:/project/training/src/com/test1/test2.txt";
String filecontent = "";
try {
File F = new file (filepathandname);
if (F.isfile () &&f.exists ()) {
InputStreamReader read = new InputStreamReader (new FileInputStream (f), "UTF-8");
BufferedReader reader=new BufferedReader (read);
String Line;
while (line = Reader.readline ()) = null) {
System.out.println (line);
}
Read.close ();
}
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Error reading file contents operation");
E.printstacktrace ();
}
There is a problem with Java IO