java read file

try(BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();

    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    }
    String everything = sb.toString();
}

0
0
Awgiedawgie 440215 points

                                    import java.io.*;

public class openFile {

    public static void main(String[] args) {
        try{
            File file = new File("C:\\file.txt");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
}

0
0
4.33
2
Bippy 8155 points

                                    try (Stream<String> stream = Files.lines(Paths.get(String.valueOf(new File("yourFile.txt"))))) {
	stream.forEach(System.out::println);
} catch (IOException e) {
	e.printStackTrace();
}

4.33 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
java 8 read file read file java java 8 read txt java read data from file java how to read a file in java how to read a fiel java java reading operations from a text file java text file reader how to open file in java get text file content java open file java reading txt file java java file java read file into a string java get al text from a file java read file text java open file how to read string from txt file java java file reading reading file in java read textfile java read file as text java read to text file java easiest method java read txt open a file java java get text from txt file how to read from a text file in java java code that opens files read text file java read data from text file in java how to open a file in java and search it read file content java java read all text in a file java read content from file read text file in java how to read text file java how to read text file wih java java code read values from a file java read a file open any file with file path with java how to open a file in java Java how to read from a text file java how to open files best way to read input from file in java how to read file in java read a text file in java read a text file using java read from a text file java how to read content of text file in java read file in java how to read from file in java how to read from text file in java read a file in java read file from text file in java file reading java how to read text file in java read contents of a text file in java java get text from file read txt file java how to read text from file in java how to read txt files in java read file java read text from file java how to read from a file in java how to read files text files in java java read from file java reading from a file how to read external file in java java read file read from file java how to read a text file in java java read txt file java read from text file java read text file
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source