打印流:PrintWriter / PrintStream
该流提供了打印方法,可以将各种数据类型的数据原样打印。
字节打印流
PrintStream
构造函数要以接收的参数类型:
1、File对象 File file
2、字符串路径 String fileName
3、字节输出流 OutputStream FileOutputStream
字符打印流
PrintWriter
构造函数要以接收的参数类型:
1、File对象 File file
2、字符串路径 String fileName
3、字节输出流 OutputStream FileOutputStream
4、字符输出流 Writer FilewWr
import java.io.*;
class PrintWriterDemo
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("aabb.txt")),true);
String line = null;
while((line=br.readLine())!=null)
{
if(line.equals("over"))
break;
out.println(line.toUpperCase());
}
out.close();
br.close();
}
class PrintWriterDemo
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("aabb.txt")),true);
String line = null;
while((line=br.readLine())!=null)
{
if(line.equals("over"))
break;
out.println(line.toUpperCase());
}
out.close();
br.close();
}
iter