Reading and displaying data from a .txt file

后端 未结 10 942
北海茫月
北海茫月 2020-11-27 15:41

How do you read and display data from .txt files?

10条回答
  •  感情败类
    2020-11-27 16:00

    public class PassdataintoFile {
    
        public static void main(String[] args) throws IOException  {
            try {
                PrintWriter pw = new PrintWriter("C:/new/hello.txt", "UTF-8");
                PrintWriter pw1 = new PrintWriter("C:/new/hello.txt");
                 pw1.println("Hi chinni");
                 pw1.print("your succesfully entered text into file");
                 pw1.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            BufferedReader br = new BufferedReader(new FileReader("C:/new/hello.txt"));
               String line;
               while((line = br.readLine())!= null)
               {
                   System.out.println(line);
               }
               br.close();
        }
    
    }
    

提交回复
热议问题