复制代码代码如下:
Импорт java.io.bufferedReader;
Импорт java.io.file;
импортировать java.io.fileinputstream;
Импорт java.io.filenotFoundException;
Импорт java.io.filereader;
импортировать java.io.ioexception;
импортировать java.io.inputstream;
Импорт java.io.reader;
открытый класс ioread {
/**
* @param args
*文件的读写
*/
public static void main (string [] args) {
// TODO Автогенерированный метод заглушка
пытаться {
// 方法一
BufferedReader BR = New BufferedReader (новый FileReader (новый файл (
"D: /project/transfar/doc/1.txt")));
// stringBuilder bd = new StringBuilder ();
StringBuffer BD = new StringBuffer ();
while (true) {
String str = br.readline ();
if (str == null) {
перерыв;
}
System.out.println (str);
Bd.Append (Str);
}
br.close ();
// System.out.println (bd.toString ());
// 方法二
InputStream IS = new FileInputStream (новый файл ("d: /project/transfar/doc/1.txt"));
Byte b [] = новый байт [integer.parseint (new File ("d: /project/transfar/doc/1.txt"). Length ()
+ "")];
is.read (b);
System.out.write (b);
System.out.println ();
is.close ();
// 方法三
Reader r = new FileReader (новый файл ("d: /project/transfar/doc/1.txt"));
char c [] = new char [(int) new File ("d: /project/transfar/doc/1.txt"). Length ()];
R.Read (C);
String str = new String (c);
System.out.print (str);
R.Close ();
} catch (runtimeexception e) {
// Todo Auto Generated Catch Blach
e.printstacktrace ();
} catch (filenotFoundException e) {
// Todo Auto Generated Catch Blach
e.printstacktrace ();
} catch (ioException e) {
// Todo Auto Generated Catch Blach
e.printstacktrace ();
}
}
}