Writing data to text file in table format

后端 未结 4 1656
感动是毒
感动是毒 2020-12-03 19:30

So far I have this:

File dir = new File(\"C:\\\\Users\\\\User\\\\Desktop\\\\dir\\\\dir1\\\\dir2);
dir.mkdirs();
File file = new File(dir, \"filename.txt\");
         


        
4条回答
  •  盖世英雄少女心
    2020-12-03 20:26

    try {
        PrintWriter outputStream = new PrintWriter("myObjects.txt");
        outputStream.println(String.format("%-20s %-20s %-20s", "Name", "Age", "Gender"));
        outputStream.println(String.format("%-20s %-20s %-20s", "John", "30", "Male"));
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题