package com.lovo.twoday;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import javax.swing.JOptionPane;
public class IOsystem {
public static void main(String[] args) {
// TODO Auto-generated method stub
Reader r = null;
try { String result = "";
r = new FileReader("data.txt");
char[] c = new char[10];
int length = 0;
while((length = r.read(c)) != -1){
String str = new String(c, 0, length);
result += str;
}
if((length = r.read(c)) == -1){
String st = "从前有座山,山里有座庙,庙里有个老和尚在讲故事。讲的什么呢?"; result = result + st;
}
System.out.println(result);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(r != null){
try {
r.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}