为什么程序总是提醒文件不存在? 文件的确是存在的

来源:4-5 字节缓冲流

leeu

2016-10-13 10:47

public static void copyFileByBuffer(File srcFile,File desFile) throws IOException{

if(!srcFile.exists()){

throw new IllegalArgumentException("The file is not exists.");

}

if(!desFile.isFile()){

throw new IllegalArgumentException("This name not target a file");

}

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(desFile));

int c;

while((c=bis.read())!=-1){

bos.write(c);

bos.flush();

}

bis.close();

bos.close();

}

public static void main(String[] args) throws IOException {

// IOunit.Outputtest();

// IOunit.FileCopy(new File("e:\\word.txt"), new File("e:\\word1.txt"));

IOunit.copyFileByBuffer(new File("E:\\迅雷下载\\weixin6327android880.apk"),

new File("E:\\迅雷下载\\XMPSetupLite-xl81.exe"));

}



错误信息:

Exception in thread "main" java.lang.IllegalArgumentException: This name not target a file

at com.wfu.IOunit.copyFileByBuffer(IOunit.java:85)

at com.wfu.IOunit.main(IOunit.java:102)


写回答 关注

1回答

  • 慕丝0809581
    2016-10-13 11:56:35
    已采纳

    apk不是文件,我是这么认为的

    leeu

    我懂了。。。。。第二个if应该写srcFile。。。。

    2016-10-14 10:26:14

    共 2 条回复 >

文件传输基础——Java IO流

为您介绍IO流的使用,以及对象的序列化和反序列化的内容

133826 学习 · 1060 问题

查看课程

相似问题