本帖最后由 Jacky_Chen1990 于 2013-5-10 00:04 编辑
先看一下代码。- package com.itheima2;
- import java.io.*;
- import java.util.*;
- public class SplitFileDemo {
- public static void main(String[] args) throws Exception {
- splitFile();
- }
-
- public static void splitFile() throws Exception {
- FileInputStream fis = new FileInputStream("D:\\a.pdf");
- FileOutputStream fos = null;
- byte[] buf = new byte[1024*1024];//为何定义为1M因为切割文件每个位1m的大小
-
- int len=0;
- int count = 1;
- while((len=fis.read(buf))!=-1) {
- fos = new FileOutputStream("D\\split\\"+(count++)+".part");
- System.out.println("D\\split\\"+(count++)+".part");
- fos.write(buf,0,len);
- fos.close();
- }
-
- if(fos!=null)
- fos.close();
- if(fis!=null)
- fis.close();
- }
- }
复制代码 以上代码,在fos = new FileOutputStream()这里提示错误,错误信息如下:- Exception in thread "main" java.io.FileNotFoundException: D\split\1.part (系统找不到指定的路径。)
- at java.io.FileOutputStream.open(Native Method)
- at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
- at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
- at com.itheima2.SplitFileDemo.splitFile(SplitFileDemo.java:19)
- at com.itheima2.SplitFileDemo.main(SplitFileDemo.java:8)
复制代码 她说找不到这个路径?这个路径明明就是存在的。。这是怎么回事呢?
|