Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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();
}
Comment

how to read from a txt file in java

try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
    String line = br.readLine();
    while (line != null) {
      	System.out.println(line);
        line = br.readLine();
    }
}
Comment

reading from a text file in java

 public static void main(String[] args) throws Exception 
  { 
    // pass the path to the file as a parameter 
    FileReader fr = new FileReader("C:UserspankajDesktop	est.txt"); 
  
    int i; 
    while ((i=fr.read()) != -1) 
      System.out.print((char) i); 
  } 
Comment

PREVIOUS NEXT
Code Example
Java :: static and final in java 
Java :: Private properties in JavaScript ES6 classes 
Java :: find if a value is in a 2d array java 
Java :: how to check if a char is a letter java 
Java :: how to find a number in a string java 
Java :: java hashmap for loop 
Java :: java array to list 
Java :: border in android 
Java :: java string to path 
Java :: what is import java.io.*? 
Java :: Display double in decimal places java 
Java :: how to print multiple lines in java 
Java :: add to array function java 
Java :: java date with T 
Java :: Java program to find the sum of first 100 numbers 
Java :: create new java swing button 
Java :: java resource file 
Java :: java game 
Java :: how to do stuff with a scoreboard minecraft 
Java :: has integer java 
Java :: turn java code to .exe 
Java :: get random string from array list 
Java :: how to convert string to boolean in java 
Java :: android date 
Java :: circular textview android 
Java :: how to make a string lowercase in java 
Java :: public String toString() { 
Java :: swing button 
Java :: jpa default value enum 
Java :: android studio constraint layout proportional height 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =