复制代码代码如下:
importar java.io.bufferedReader;
importar java.io.file;
importar java.io.fileInputStream;
importar java.io.filenotfoundException;
importar java.io.fileReader;
importar java.io.ioException;
importar java.io.inputStream;
importar java.io.Reader;
classe pública ioread {
/**
* @param args
*文件的读写
*/
public static void main (string [] args) {
// TODO Method Stub
tentar {
// 方法一
BUBLESEDRADER BR = new BufferredReader (new FileReader (novo arquivo (
"D: /project/transfar/doc/1.txt")));
// stringbuilder bd = new stringbuilder ();
Stringbuffer bd = new StringBuffer ();
while (true) {
String str = Br.readline ();
if (str == null) {
quebrar;
}
System.out.println (str);
bd.append (str);
}
br.close ();
// System.out.println (bd.toString ());
// 方法二
InputStream is = new FileInputStream (novo arquivo ("d: /project/transfar/doc/1.txt"));
byte b [] = novo byte [Integer.parseint (novo arquivo ("d: /project/transfar/doc/1.txt"). comprimento ()
+ "")];
is.read (b);
System.out.write (b);
System.out.println ();
is.close ();
// 方法三
Leitor r = new fileReader (novo arquivo ("d: /project/transfar/doc/1.txt"));
char c [] = novo char [(int) novo arquivo ("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 BLOCO DE CAPAGEM AUTOMAGEM
E.PrintStackTrace ();
} catch (filenotfoundException e) {
// TODO BLOCO DE CAPAGEM AUTOMAGEM
E.PrintStackTrace ();
} catch (ioexception e) {
// TODO BLOCO DE CAPAGEM AUTOMAGEM
E.PrintStackTrace ();
}
}
}