首页 > 代码库 > java 流 写
java 流 写
package 流;import java.io.BufferedWriter;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.OutputStream;public class 写 { public static String path="d://test.txt"; public static void main(String[] args) { BufferedWriterDemo(); } //字节流 public static void OutputStream(){ try { OutputStream outputStream=new FileOutputStream(path); String str="hello world"; byte[] b=str.getBytes(); for(int i=0; i<b.length; i++) try { outputStream.write(b[i]); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //字符流 public static void FileWriterDemo(){ FileWriter fileWriter; try { fileWriter = new FileWriter(path); String str="hello word"; fileWriter.write(str); fileWriter.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //缓冲流 public static void BufferedWriterDemo(){ BufferedWriter bufferedWriter; try { bufferedWriter = new BufferedWriter(new FileWriter(path)); String str="hello word"; bufferedWriter.write(str); bufferedWriter.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
java 流 写
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。