zoukankan      html  css  js  c++  java
  • java源码整合

    公司要申请项目著作权,需要将源码整合到一起打印出来。写的一段整合的代码,跟大家分享下:

    源码:

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintStream;
    import java.util.Properties;

    public class Merge {
        static String folderPath = "D:/src/";
        
        public void Merge(){
             InputStream in = this.getClass().getClassLoader().getResourceAsStream("folderpath.properties");
             Properties p = new Properties();
             try {
                p.load(in);
                folderPath = p.getProperty("folderpath");
                System.out.println(folderPath);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    public static void go() {

            System.out.println("开始读取文件夹中文档 》》》");

            File file = new File(folderPath);

            System.out.println(folderPath);
            
            analysisDir(file);
            
            System.out.println("合并数据完成《《《");
        }

        public static Boolean isDir(File file) {
            if (file.isDirectory())
                return true;
            return false;
        }

     
        public static void analysisDir(File file) {
            if (isDir(file)) {
                File[] files = file.listFiles();
                for (File tempFile : files) {
                    analysisDir(tempFile);
                }
            } else {
                String fileName = file.getName();
                System.out.println(fileName);
                if (fileName.indexOf(".java")>0) {
                    File unionFile = new File(folderPath + "union.txt");
                    String line = "";
                    FileInputStream fis;
                    try {
                        fis = new FileInputStream(file);
                        //设置编码,以防乱码
                        InputStreamReader brs = new InputStreamReader(fis,"utf-8");
                        BufferedReader br = new BufferedReader(brs);
                        //仍然乱码,在设置输出编码
                        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(unionFile,true),"utf-8");
                        //FileWriter writer = new FileWriter(unionFile, true);
                        BufferedWriter bw = new BufferedWriter(writer);
                        while ((line = br.readLine()) != null) {
                            System.out.println(line);
                            bw.write(line);
                            bw.newLine();

              //不要忘记flush().
                            bw.flush();
                            //System.setOut(new PrintStream(new FileOutputStream(folderPath + "output.txt")));
                        }
                        //brs.close();
                        writer.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

  • 相关阅读:
    (OK) Use Android Code to Enable USB Debugging
    add software "mouse cursor" in Android-x86
    Subject: [android-porting] Mouse cursor:issue with dispatchPointer
    BUG实例分析五:binder alloc buf, no vma
    【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets
    【ACM-ICPC 2018 南京赛区网络预赛 I】Skr
    【ACM-ICPC 2018 南京赛区网络预赛 A】An Olympian Math Problem
    【AIM Tech Round 5 (rated, Div. 1 + Div. 2) 总结】【题解往前或往后翻,不在这】
    【AIM Tech Round 5 (rated, Div. 1 + Div. 2) A】 Find Square
    【AIM Tech Round 5 (rated, Div. 1 + Div. 2) B】Unnatural Conditions
  • 原文地址:https://www.cnblogs.com/benjia/p/3819560.html
Copyright © 2011-2022 走看看