| 
 
 拆分文件始终做的一件事就是熟悉 类名以及及其方法  以下代码 未写出FileInputStream 和 FileOutputSgtream  的声明。  
        FileInputStream f = null;
        FileOutputStream f2 = null;
 
        try {
            File file = new File("d:/LOLFolder/langs.model.xml");
            long count = file.length();
            int l = (int)count / 102400;
            
            l++;
            
            int b = (int)count % 102400;
            f = new FileInputStream(file);
            
            byte[] bytes = new byte[102400];
            String path = "d:/LOLFolder/eclipse.exe-";
            for (int i = 0 ; i < l; i++){
                File f1 = new File(path + i);
                if (!f1.exists()){
                    f1.createNewFile();
                    f2 = new FileOutputStream(f1);
                    int read = f.read(bytes);
                    f2.write(bytes);
                    System.err.println(read);
                }
            }
 
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try {
                if (f != null){
                    f.close();
                }
                if (f2 != null){
                    f2.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  
这部分代码 是借鉴的别人的 一开始自己毫无头绪 但是看了他的之后 发现是纯学过的方法调用  
1、首先创建 输入输出流 之后放入try catch 里捕抓异常  2、try里面实例化FileInputStream 和 FileOutputSgtream  引用对其方法进行调用 从而实现  
发现我在思考的时候有个地方忽略:  也就是——这个是字节流 那么可以直接用整数型数值放入  read(); 和 write(); 两个方法中对其相应字节大小的内容进行读取或写入 为方便读取或者写入多大的 自然获取其文件长度 存入数组 再以数组形式进行。  补充:  以read(); 和 write(); 最终得出的是文件字节大小  其内容时通过各个数据类型的数组包含 之后通过这两个方法进行操作 它们本身不含内容  
 int ss=fg1.read(A);
            	System.out.println(ss);
  
不是具体的文件内容  
也就是以下这段:  
 byte[] bytes = new byte[102400];
            String path = "d:/LOLFolder/eclipse.exe-";
            for (int i = 0 ; i < l; i++){
                File f1 = new File(path + i);
                if (!f1.exists()){
                    f1.createNewFile();
                    f2 = new FileOutputStream(f1);
                    int read = f.read(bytes);
                    f2.write(bytes);
                    System.err.println(read);
  
l 是输出拆分文件的序号 不存在就创建 再实例化输出流 读取  每次只读取102400字节大小的文件也就到达了分割的目的 因为在这之前已经处理出具体的分割次数 只需要读取就好  
合并最主要的就是用到 File型数组 记住数组不是只运用于数字 根据不同数据类型 可以利用数组的特点实现该数据类型的某些算法  示例:  
 File f1 = new File("C:\\Users\\logic\\Desktop\\需求说明.docx-0");
        File f2 = new File("C:\\Users\\logic\\Desktop\\需求说明.docx-1");
        File f3 = new File("C:\\Users\\logic\\Desktop\\需求说明.docx-2");
        File f4 = new File("C:\\Users\\logic\\Desktop\\需求说明.docx-3");
        File f5 = new File("C:\\Users\\logic\\Desktop\\需求说明.docx-4");
        File file = new File("C:\\Users\\logic\\Desktop\\需求说明new.docx");
        try{
            FileOutputStream fos = new FileOutputStream(file);      
            File[] f = {f1, f2, f3, f4, f5};
            for (int i = 0; i < f.length; i++) {
                byte[] b = new byte[(int)f[i].length()];
                FileInputStream fis = new FileInputStream(f[i]);
                fis.read(b);
                fis.close();    
                fos.write(b);
                fos.flush();
                System.out.printf("把子文件:%s写出到目标文件中%n", f[i]);
            }
            fos.close();
              System.out.printf("最后目标文件的大小:%,d字节", file.length());
        }catch(IOException exception){
            exception.printStackTrace();
        }
 
                
                
                
        
    
 
 |