读文件写进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();
        }
    }

  

posted @ 2020-12-08 16:18  qtqx  阅读(104)  评论(0)    收藏  举报