1. 程式人生 > 實用技巧 >讀檔案寫進mysql中

讀檔案寫進mysql中

public void ts()  {
        
        char CHAR_SPLIT = 0x1b;
        
        try {
            File file = new File("/Users/chen/Downloads/test.txt");
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
                BufferedReader reader = new BufferedReader(read);
                String line;
                while ((line = reader.readLine()) != null) {
                    //System.out.println(line);
                    StringBuffer sb = new StringBuffer();
                    sb.append(CHAR_SPLIT);
                    //一行資料 通過分隔符分割 成陣列  在轉成list
                    List<String> list = Arrays.asList(line.split(String.valueOf((sb))));
                    /**
                     * 然後去就是把list中的值set進實體中
                     * 然後insert
                     */
                }
                read.close();
            }
        } catch (Exception e) {
            System.out.println("讀取檔案內容操作出錯");
            e.printStackTrace();
        }
    }