public static void main(String[] args) throws IOException { String path = "D:\\project\\luotuo-server\\src\\test\\java\\com\\manageSystem\\project\\lt\\service\\impl\\db_dump.sql"; File file = new File(path); //151382 InputStream inputStream = new FileInputStream(file); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line = bufferedReader.readLine(); Stream<String> lines = bufferedReader.lines(); lines = lines.limit(151382); FileOutputStream fileOutputStream = new FileOutputStream("a.txt"); // BufferedWriter writer = new BufferedWriter(); try { lines.forEach(p->{ //写数据到文件 try { fileOutputStream.write(p.getBytes()); fileOutputStream.write("\r\n".getBytes()); } catch (IOException e) { e.printStackTrace(); } System.out.println("haha"); }); } finally { if(fileOutputStream != null){ fileOutputStream.close(); } if(bufferedReader != null) { bufferedReader.close(); } if (inputStreamReader != null) { inputStreamReader.close(); } if(inputStream != null ) { inputStream.close(); } System.out.println("chegn"); } }
本文来自博客园,作者:狂躁的键盘,转载请注明原文链接:https://www.cnblogs.com/wangweiip/p/16966964.html