複製程式碼如下:
嘗試 {
// 方法一
BufferedReader br = 新 BufferedReader(新 FileReader(新檔案(
“D://1.xls”)));
// StringBuilder bd = new StringBuilder();
StringBuffer bd = new StringBuffer();
而(真){
String str = br.readLine();
if (str == null) {
休息;
}
System.out.println(str);
bd.append(str);
}
br.close();
// System.out.println(bd.toString());
// 方法二
輸入流 = new FileInputStream(new File("d://1.xls"));
位元組 b[] = new byte[Integer.parseInt(new File("d://1.xls").length()
+“”)];
is.read(b);
System.out.write(b);
System.out.println();
is.close();
// 方法三
讀取器 r = new FileReader(new File("d://1.xls"));
char c[] = new char[(int) new File("d://1.xls").length()];
r.read(c);
字串 str = 新字串(c);
System.out.print(str);
r.close();
} catch (RuntimeException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
} catch (IOException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
}