Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

What's the process of a Java print file?

Asked by Amit Sinha Oct 14, 2022 1.2K views 1 answer
Share

About this question

I am trying to read lines from a text file in Java, but there is a lot going on. Is this the best way to do this? I am especially concerned with resource leaks.

import java.io.*;


public class Filing {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        FileReader fr = new FileReader("/Users/thomas povinelli/Desktop/apps.txt");
        BufferedReader br = new BufferedReader(fr);
        String buffer;
        String full text="";
        while ((buffer = br.readLine()) != null) {
            System.out.println(buffer);
            full text += buffer;
        }
        br.close();
        fr.close();
    }
}

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.