System.setOut(file);public static void setOut(PrintStream out) Reassigns the "standard" output stream. First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.Parameters:out - the new standard output stream
旧事重提: import java.io.*; import java.util.Date; import java.lang.String; import java.text.SimpleDateFormat; public class WriteLog { // public static void main(String[] args) { public WriteLog(){} static void WriteMsg(String line){ try { SimpleDateFormat formatter = new SimpleDateFormat ("MMdd_yy"); Date currentTime_1 = new Date(); String dateString = formatter.format(currentTime_1); String filename = "Log"+dateString ; FileWriter output = new FileWriter(filename); // output.write(line, 0, line.length()); String str=""; str=str + line; output.write(str+ "\r"); // Output.newLine();
Reassigns the "standard" output stream. First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.Parameters:out - the new standard output stream
import java.io.*;
import java.util.Date;
import java.lang.String;
import java.text.SimpleDateFormat; public class WriteLog {
// public static void main(String[] args) {
public WriteLog(){}
static void WriteMsg(String line){
try {
SimpleDateFormat formatter = new SimpleDateFormat ("MMdd_yy");
Date currentTime_1 = new Date();
String dateString = formatter.format(currentTime_1);
String filename = "Log"+dateString ; FileWriter output = new FileWriter(filename);
// output.write(line, 0, line.length());
String str="";
str=str + line;
output.write(str+ "\r");
// Output.newLine();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
用filewriter可以么?如果文件已存在,又该怎么控制?请指点,我对流操作不是很熟!