java中新建文件,终于成功了!

今天,文件的新建问题终于解决了,也就是说,到现在,已经对文件的原理和构造有了初步的认识,因为,

文件本身包含了很多的东西,我相信,懂了其中的一个,其他的理解起来就不会很难的!

FileInputStream类在创建文件的时候,
如果文件不存在的话,会自动创建这个文件。

import java.io.*;
public class DuJian {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO 自动生成方法存根
  try{
   FileInputStream fileinputstream=new FileInputStream(args[0]);

//以这种方式打开文件。
   FileOutputStream fileoutputstream =new FileOutputStream(args[1]);
   byte[] buffer=new byte[1024];
   while (true){
   if (fileinputstream.available()<1024){
            int num =-1;
    while((num=fileinputstream.read())!=-1){
     fileoutputstream.write(num);
    }
    break;
   }
   else
   {
    fileinputstream.read(buffer);
    fileoutputstream.write(buffer);
   }
   fileinputstream.close();
   fileoutputstream.close();
   }
  }catch(ArrayIndexOutOfBoundsException e){
   System.out.print("meiyouzhidingwenjian");}
  catch(IOException e){e.printStackTrace();}
  

}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值