package daima;
import java.io.*;
public class transmit {
 public static void main(String[] args) throws IOException{
  File file=new File("data.text");
  System.out.println("文件是否存在?"+file.exists());
 try{
  if(!file.exists()){
   boolean b=file.createNewFile();
   System.out.println("文件是否创建成功?"+b);
   if(b==true){
    System.out.println("文件路径为:"+file.getAbsolutePath());
   }
  } 
 }catch(Exception e){
  System.out.println("文件创建中出现错误!");
 } 
   String str ="12345abcdef@#%&*软件工程";
   FileOutputStream fos=new FileOutputStream("data.text");
   byte[] buff=str.getBytes();
   fos.write(buff);
   fos.close();
   FileInputStream fis=new FileInputStream(file);
   byte[] buf=new  byte[(int)file.length()];
   fis.read(buf);
   String s=new String(buf);
   System.out.println(s);
   fis.close();
 }}
 

 

 

这次上级分清楚了输入流以及输出流还有read、write类

输入输出流难以理解    最应分清的是以谁为参照

 

posted on 2019-06-19 12:55  卢思林  阅读(144)  评论(0编辑  收藏  举报