标题: How to keep stream open? [打印本页] 作者: zhshqzyc 时间: 2007-04-22 09:27 标题: How to keep stream open? We all know write a string to a file is simple. Such as:
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
复制代码
I have a case which needs write strings in many methods.
How can I pass file name or stream and implement it?
(Open the stream, pass the stream into each method)
public void doDiff(String oldFile, String newFile, String Directory) {