• Java实现按行拆分pdf


    /** 
         * 按行分割文件 
         * @param rows 为多少行一个文件  
         * @param sourceFilePath 为源文件路径  
         * @param targetDirectoryPath 文件分割后存放的目标目录 
         */  
        public void splitDataToSaveFile(int rows, String sourceFilePath,  
                String targetDirectoryPath) {  
            long start1 = System.currentTimeMillis();  
              
            File sourceFile = new File(sourceFilePath);  
            File targetFile = new File(targetDirectoryPath);  
            if (!sourceFile.exists() || rows <= 0 || sourceFile.isDirectory()) {  
                return;  
            }  
            if (targetFile.exists()) {  
                if (!targetFile.isDirectory()) {  
                    return;  
                }  
            } else {  
                targetFile.mkdirs();  
            }  
            try {  
      
                InputStreamReader in = new InputStreamReader(new FileInputStream(sourceFilePath),"GBK");  
                BufferedReader br=new BufferedReader(in);  
                  
                BufferedWriter bw = null;  
                String str = "";  
                String tempData = br.readLine();  
                int i = 1, s = 0;  
                long start2 = System.currentTimeMillis();  
                while (tempData != null) {  
                    str += tempData + "
    ";  
                    if (i % rows == 0) {  
                        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(   
                                targetFile.getAbsolutePath() + "/" +  sourceFile.getName() +"_" + (s+1) +".csv"), "GBK"),1024);   
                          
                        bw.write(str);  
                        bw.close();  
                          
                        str = "";  
                        start2 = System.currentTimeMillis();  
                        s += 1;  
                    }  
                    i++;  
                    tempData = br.readLine();  
                }  
                if ((i - 1) % rows != 0) {  
                      
                    bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(   
                            targetFile.getAbsolutePath() + "/" +  sourceFile.getName() +"_" + (s+1) +".csv"), "GBK"),1024);   
                    bw.write(str);  
                    bw.close();  
                    br.close();  
                      
                    s += 1;  
                }  
                in.close();  
                  
            } catch (Exception e) {  
            }  
        }  
    

      

  • 相关阅读:
    Qt 多线程使用moveToThread
    FFmpeg下载地址
    选择排序
    数据结构和算法之时间复杂度和空间复杂度
    嵌入式动态库查看需要的依赖库
    Q_UNUSED 的使用
    php对csv文件的读取,写入,输出下载操作
    python一个简单的登录
    python的反射
    python类的特性
  • 原文地址:https://www.cnblogs.com/dreammyone/p/7478856.html
Copyright © 2020-2023  润新知