import java.io.FileNotFoundException;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import java.util.HashMap;import java.util.List;import java.util.Set;import java.util.concurrent.atomic.AtomicInteger;public class PrintWriterTest { public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException { PrintWriter writer = new PrintWriter(“the-file-name.txt”, “UTF-8”); writer.println(“The first line”); writer.println(“The second line”); writer.close(); } public static void printFile(String fileName, HashMap<String, List> map) { int size = 4000; Set set = map.keySet(); set.forEach(key -> { List list = map.get(key); int max = 1; int page = 1; boolean flag = true; do { max = page * size; if (max >= list.size()) { max = list.size(); flag = false; } try { PrintWriter writer = new PrintWriter(fileName + “-” + key + “-” + max, “UTF-8”); for (int i = (page - 1) * size; i < max; i++) { writer.println(list.get(i) + “,”); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } page++; } while (flag); }); }}
printwriter
最新推荐文章于 2023-02-08 10:40:41 发布