标签:adl 节点 static 判断 code nbsp oid exception put
import java.io.*; public class FileReaderWriter { public static void main(String[] args) throws IOException { File file=new File("d://text.txt");//创建文件对象 if (!file.exists()){//判断文件是否存在 file.createNewFile();//创建text.txt文件 //创建缓冲输入流,BufferedWriter是包装流,参数里属于节点流,参数为应Writer,由于Writer为抽象类 // 所以写入Writer的子类FileOutputStream流 BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); bw.write("Java 输出流");//BufferedWriter可以直接写入一个字符串,写入text.txt bw.flush();//刷新 bw.close();//关闭流 //缓冲输出流,类似BufferedWriter BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file))); String result=null;//字符串初始化为空 while((result=br.readLine())!=null){//直接读取一行字符串赋值给String对象 System.out.println(result);//输出一行字符串 } br.close();//关闭输出流 } } }
BufferedWriter和BufferedReader使用
标签:adl 节点 static 判断 code nbsp oid exception put
原文地址:https://www.cnblogs.com/liushili/p/14108056.html