├── .gitignore ├── lib ├── c3p0-0.9.5.2.jar ├── javacsv-2.1.jar ├── commons-io-2.6.jar ├── mchange-commons-java-0.2.11.jar └── mysql-connector-java-5.1.40-bin.jar ├── src ├── main │ └── RUN.java ├── c3p0-config.xml ├── dao │ └── Data.java ├── util │ ├── C3P0Connection.java │ └── AutoWrite.java └── listener │ ├── DicListenner.java │ └── Transfer.java ├── .project ├── .settings └── org.eclipse.jdt.core.prefs └── .classpath /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /lib/c3p0-0.9.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackmodeN/CSVEncoders/HEAD/lib/c3p0-0.9.5.2.jar -------------------------------------------------------------------------------- /lib/javacsv-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackmodeN/CSVEncoders/HEAD/lib/javacsv-2.1.jar -------------------------------------------------------------------------------- /lib/commons-io-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackmodeN/CSVEncoders/HEAD/lib/commons-io-2.6.jar -------------------------------------------------------------------------------- /lib/mchange-commons-java-0.2.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackmodeN/CSVEncoders/HEAD/lib/mchange-commons-java-0.2.11.jar -------------------------------------------------------------------------------- /lib/mysql-connector-java-5.1.40-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlackmodeN/CSVEncoders/HEAD/lib/mysql-connector-java-5.1.40-bin.jar -------------------------------------------------------------------------------- /src/main/RUN.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import java.util.Scanner; 4 | 5 | import listener.DicListenner; 6 | 7 | public class RUN { 8 | public static void main(String[] args) { 9 | 10 | DicListenner.start(); 11 | Scanner in = new Scanner(System.in); 12 | while(in.hasNext()){ 13 | if(in.nextLine().equals("exit")){ 14 | System.exit(0); 15 | } 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 转码工具 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /src/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | jdbc:mysql://localhost:3306/script?useSSL=false&useUnicode=true&characterEncoding=utf-8 8 | com.mysql.jdbc.Driver 9 | root 10 | 123456 11 | 12 | 5 13 | 20 14 | 20 15 | 50 16 | 17 | 18 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/dao/Data.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import util.C3P0Connection; 9 | 10 | public class Data { 11 | public static String Find(String query) throws SQLException { 12 | Connection conn = C3P0Connection.getInstance().getConnection(); 13 | String sql = "SELECT * FROM DATABASE$ WHERE 主机ip = ?"; 14 | String result = "无数据"; 15 | if(query==null){ 16 | return result; 17 | } 18 | try { 19 | PreparedStatement ps = conn.prepareStatement(sql); 20 | ps.setString(1, query); 21 | ResultSet rs = ps.executeQuery(); 22 | while(rs.next()){ 23 | if (rs.getString(" 项目") != null) 24 | result = rs.getString(" 项目"); 25 | 26 | 27 | } 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | conn.close(); 32 | return result; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/util/C3P0Connection.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | import com.mchange.v2.c3p0.ComboPooledDataSource; 7 | 8 | 9 | 10 | public class C3P0Connection { 11 | private static C3P0Connection instance; 12 | 13 | private static ComboPooledDataSource dataSource; 14 | 15 | private C3P0Connection() throws Exception { 16 | dataSource = new ComboPooledDataSource(); 17 | } 18 | 19 | /** 20 | * 获取实例 21 | * @return 22 | */ 23 | public static final C3P0Connection getInstance() { 24 | if (instance == null) { 25 | try { 26 | instance = new C3P0Connection(); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | return instance; 32 | } 33 | 34 | /** 35 | * 获取数据库连接 36 | * @return 37 | */ 38 | public synchronized final Connection getConnection() { 39 | Connection conn = null; 40 | try { 41 | conn = dataSource.getConnection(); 42 | 43 | } catch (SQLException e) { 44 | e.printStackTrace(); 45 | } 46 | return conn; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/util/AutoWrite.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.io.IOException; 4 | import java.nio.charset.Charset; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.csvreader.CsvReader; 9 | import com.csvreader.CsvWriter; 10 | 11 | import dao.Data; 12 | 13 | public class AutoWrite { 14 | private List list = new ArrayList<>(); 15 | 16 | private int j=0; 17 | private String name; 18 | 19 | 20 | public void write(String filePath) { 21 | 22 | 23 | try { 24 | // 创建CSV写对象 25 | CsvWriter csvWriter = new CsvWriter(filePath, ',', Charset.forName("GBK")); 26 | // CsvWriter csvWriter = new CsvWriter(filePath); 27 | 28 | // 把数据逐行写入 29 | for(String[] content:list) 30 | csvWriter.writeRecord(content); 31 | csvWriter.close(); 32 | 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | public String getRealName(CsvReader csvReader) throws Throwable { 38 | String man = csvReader.get(1); 39 | return Data.Find(man); 40 | 41 | } 42 | 43 | public void read(String filePath) throws Throwable { 44 | 45 | 46 | 47 | try { 48 | // 创建CSV读对象 49 | CsvReader csvReader = new CsvReader(filePath, ',', Charset.forName("GBK")); 50 | 51 | // 读表头 52 | csvReader.readHeaders(); 53 | 54 | 55 | while (csvReader.readRecord()) { 56 | if(j==0){ 57 | name = this.getRealName(csvReader)+","; 58 | j=1; 59 | } 60 | // 读一整行 61 | if (csvReader.getRawRecord().indexOf("问题") != -1){ 62 | // System.out.println(csvReader.getRawRecord()); 63 | String temp = (name+csvReader.getRawRecord()).replaceAll("\"",""); 64 | 65 | list.add(temp.split(",")); 66 | // 读这行的某一列 67 | // System.out.println(csvReader.get("问题")); 68 | } 69 | } 70 | 71 | } catch (IOException e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/listener/DicListenner.java: -------------------------------------------------------------------------------- 1 | package listener; 2 | 3 | import java.io.File; 4 | 5 | import org.apache.commons.io.FileUtils; 6 | import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; 7 | import org.apache.commons.io.monitor.FileAlterationMonitor; 8 | import org.apache.commons.io.monitor.FileAlterationObserver; 9 | 10 | public final class DicListenner { 11 | private static FileAlterationMonitor monitor; 12 | 13 | private static final String My_DIR = "C:\\Users\\DELL-5490\\Documents\\problem"; 14 | 15 | public static void start() { 16 | registerListenner(); 17 | try { 18 | monitor.start(); 19 | } catch (Exception e) { 20 | // TODO Auto-generated catch block 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public static void close() { 26 | try { 27 | monitor.stop(); 28 | } catch (Exception e) { 29 | // TODO Auto-generated catch block 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | public static void registerListenner() { 35 | System.out.println("File Monitor create..."); 36 | 37 | // File Monitoring 38 | 39 | // Create a new observer for the folder and add a listener 40 | // that will handle the events in a specific directory and take action. 41 | File parentDir = FileUtils.getFile(My_DIR); 42 | 43 | FileAlterationObserver observer = new FileAlterationObserver(parentDir); 44 | observer.addListener(new FileAlterationListenerAdaptor() { 45 | 46 | @Override 47 | public void onFileCreate(File file) { 48 | try { 49 | Transfer.TransCode(file); 50 | } catch (Throwable e) { 51 | // TODO Auto-generated catch block 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | @Override 57 | public void onFileDelete(File file) { 58 | System.out.println("File deleted: " + file.getName()); 59 | } 60 | 61 | @Override 62 | public void onDirectoryCreate(File dir) { 63 | System.out.println("Directory created: " + dir.getName()); 64 | } 65 | 66 | @Override 67 | public void onDirectoryDelete(File dir) { 68 | System.out.println("Directory deleted: " + dir.getName()); 69 | } 70 | }); 71 | 72 | // Add a monior that will check for events every x ms, 73 | // and attach all the different observers that we want. 74 | monitor = new FileAlterationMonitor(500, observer); 75 | 76 | } 77 | } -------------------------------------------------------------------------------- /src/listener/Transfer.java: -------------------------------------------------------------------------------- 1 | 2 | package listener; 3 | 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.FilenameFilter; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | import java.io.OutputStream; 11 | import java.io.OutputStreamWriter; 12 | import java.nio.charset.Charset; 13 | import java.nio.charset.UnsupportedCharsetException; 14 | 15 | import util.AutoWrite; 16 | 17 | 18 | public class Transfer { 19 | private static String path; 20 | 21 | 22 | 23 | public static void TransCode(File url) throws Throwable{ 24 | path = url.getAbsolutePath(); 25 | String name = url.getName(); 26 | if (url.exists()) { 27 | System.out.println("当前正在处理文件编号:"+name); 28 | convert(path, "UTF-8", "GBK", new FilenameFilter() { 29 | @Override 30 | public boolean accept(File dir, String name) { 31 | return name.endsWith("csv"); 32 | } 33 | }); 34 | } 35 | AutoWrite aw = new AutoWrite(); 36 | aw.read(path); 37 | aw.write(path); 38 | System.out.println(name+"处理完毕"); 39 | 40 | } 41 | 42 | 43 | 44 | /** 45 | * 把指定文件或目录转换成指定的编码 46 | * 47 | * @param fileName 48 | * 要转换的文件 49 | * @param fromCharsetName 50 | * 源文件的编码 51 | * @param toCharsetName 52 | * 要转换的编码 53 | * @throws Exception 54 | */ 55 | public static void convert(String fileName, String fromCharsetName, String toCharsetName) throws Exception { 56 | convert(new File(fileName), fromCharsetName, toCharsetName, null); 57 | } 58 | 59 | /** 60 | * 把指定文件或目录转换成指定的编码 61 | * 62 | * @param file 63 | * 要转换的文件或目录 64 | * @param fromCharsetName 65 | * 源文件的编码 66 | * @param toCharsetName 67 | * 要转换的编码 68 | * @throws Exception 69 | */ 70 | public static void convert(File file, String fromCharsetName, String toCharsetName) throws Exception { 71 | convert(file, fromCharsetName, toCharsetName, null); 72 | } 73 | 74 | /** 75 | * 把指定文件或目录转换成指定的编码 76 | * 77 | * @param file 78 | * 要转换的文件或目录 79 | * @param fromCharsetName 80 | * 源文件的编码 81 | * @param toCharsetName 82 | * 要转换的编码 83 | * @param filter 84 | * 文件名过滤器 85 | * @throws Exception 86 | */ 87 | public static void convert(String fileName, String fromCharsetName, String toCharsetName, FilenameFilter filter) 88 | throws Exception { 89 | convert(new File(fileName), fromCharsetName, toCharsetName, filter); 90 | } 91 | 92 | /** 93 | * 把指定文件或目录转换成指定的编码 94 | * 95 | * @param file 96 | * 要转换的文件或目录 97 | * @param fromCharsetName 98 | * 源文件的编码 99 | * @param toCharsetName 100 | * 要转换的编码 101 | * @param filter 102 | * 文件名过滤器 103 | * @throws Exception 104 | */ 105 | public static void convert(File file, String fromCharsetName, String toCharsetName, FilenameFilter filter) 106 | throws Exception { 107 | if (file.isDirectory()) { 108 | File[] fileList = null; 109 | if (filter == null) { 110 | fileList = file.listFiles(); 111 | } else { 112 | fileList = file.listFiles(filter); 113 | } 114 | for (File f : fileList) { 115 | convert(f, fromCharsetName, toCharsetName, filter); 116 | } 117 | } else { 118 | if (filter == null || filter.accept(file.getParentFile(), file.getName())) { 119 | String fileContent = getFileContentFromCharset(file, fromCharsetName); 120 | saveFile2Charset(file, toCharsetName, fileContent); 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * 以指定编码方式读取文件,返回文件内容 127 | * 128 | * @param file 129 | * 要转换的文件 130 | * @param fromCharsetName 131 | * 源文件的编码 132 | * @return 133 | * @throws Exception 134 | */ 135 | public static String getFileContentFromCharset(File file, String fromCharsetName) throws Exception { 136 | if (!Charset.isSupported(fromCharsetName)) { 137 | throw new UnsupportedCharsetException(fromCharsetName); 138 | } 139 | InputStream inputStream = new FileInputStream(file); 140 | InputStreamReader reader = new InputStreamReader(inputStream, fromCharsetName); 141 | char[] chs = new char[(int) file.length()]; 142 | reader.read(chs); 143 | String str = new String(chs).trim(); 144 | reader.close(); 145 | return str; 146 | } 147 | 148 | /** 149 | * 以指定编码方式写文本文件,存在会覆盖 150 | * 151 | * @param file 152 | * 要写入的文件 153 | * @param toCharsetName 154 | * 要转换的编码 155 | * @param content 156 | * 文件内容 157 | * @throws Exception 158 | */ 159 | public static void saveFile2Charset(File file, String toCharsetName, String content) throws Exception { 160 | if (!Charset.isSupported(toCharsetName)) { 161 | throw new UnsupportedCharsetException(toCharsetName); 162 | } 163 | OutputStream outputStream = new FileOutputStream(file); 164 | OutputStreamWriter outWrite = new OutputStreamWriter(outputStream, toCharsetName); 165 | outWrite.write(content); 166 | outWrite.close(); 167 | } 168 | } --------------------------------------------------------------------------------