//这是一个典型的从文件读取然后写入文件的方法
File fileDir = new File("c://temp//child" + File.separatorChar);
if (!fileDir.isDirectory()) {
fileDir.mkdirs();
} else {
System.out.println("has exist");
}
File fileOld = new File(fileDir.getPath() + File.separatorChar
+ "buffer.txt");
File file = new File(fileDir.getPath() + File.separatorChar
+ "buffer1.txt");
BufferedReader in = new BufferedReader(new FileReader(fileOld));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file,true)));
int count = 1;
String s;
while((s=in.readLine())!=null){
out.println(count++ + ":" + s);
}
out.close();
//当输出可供另一个stream的情况.txt
File fileDir = new File("c://temp//child" + File.separatorChar);
if (!fileDir.isDirectory()) {
fileDir.mkdirs();
} else {
System.out.println("has exist");
}
File fileOld = new File(fileDir.getPath() + File.separatorChar
+ "buffer.txt");
File file = new File(fileDir.getPath() + File.separatorChar
+ "buffer1.txt");
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
out.writeDouble(3.14159);
String s = "中国";
out.write(s.getBytes(),0,s.getBytes().length);
//out.writeChars("中国this is the value of pi/n");
out.writeBytes("this is the value of pi/n");
out.writeBytes("this is the value of pi/2/n");
//out.writeDouble(3.14159/2);
out.close();
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
System.out.println(in.readDouble());
System.out.println(inbr.readLine());
System.out.println(inbr.readLine());
//System.out.println(inbr.readLine());
//System.out.println(in.readDouble());