今天,文件的新建问题终于解决了,也就是说,到现在,已经对文件的原理和构造有了初步的认识,因为,
文件本身包含了很多的东西,我相信,懂了其中的一个,其他的理解起来就不会很难的!
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();}
}
}