Answers for "java read file"

6

java read file text

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();
}
Posted by: Guest on March-12-2020
2

open file java

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();
        }
    }
    
}
Posted by: Guest on October-22-2020
3

java read file

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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language