打印流:
该流提高打印方法,可以将各类进行打印
字节打印流:printsteam 能直接操作文件
构造函数能够接受的参数类型:
1;file对象
2,字符串路径。string
3;字节输出流。outputstream
没有字节输出流
字符打印流:printwriter
1;file对象
2,字符串路径。string
3,字节输出流。outputstream
该流提高打印方法,可以将各类进行打印
字节打印流:printsteam 能直接操作文件
构造函数能够接受的参数类型:
1;file对象
2,字符串路径。string
3;字节输出流。outputstream
没有字节输出流
字符打印流:printwriter
1;file对象
2,字符串路径。string
3,字节输出流。outputstream
4,字符输出流,writer
public class Ioprint流 {
public static void main(String[] args)throws IOException
{
BufferedReader buf =
new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("d:\\count.txt",true)),true);//true自动刷新
String line= null;
while((line = buf.readLine())!=null)
{
out.println(line);
//out.flush();
}
out.close();
buf.close();
}
}
以下是一个异常信息的写入,通过print流
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.crypto.Data;
public class Io4yichangrizhi {
public static void main(String[] args)throws IOException
{
try{
int[] arr=new int[2];
System.out.println(arr[3]);
}
catch(Exception e)
{
try{
//Data d = new Date();
Date d = new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s=sdf.format(d);//将时间格式化
PrintStream ps = new PrintStream("e://exexeption.log");// 创建具有指定文件名称且不带自动行刷新的新打印流
ps.print(s);
System.setOut(ps);
}
catch(IOException e1)
{
throw new RuntimeException("创建失败");
}
e.printStackTrace(System.out);
}
}
}