java how to read a text file
Java
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
public class ReadFile {
public static void main(String[] args) {
try {
File myObj = new File("filename.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
System.out.println(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class Scratch{
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("filename"));
input.next(); //returns next String
input.nextLine(); //returns next Line
input.nextBoolean();//returns next Boolean
input.nextInt(); //returns next Int
input.nextDouble(); //returns next double
...
}
}
Also in Java:
- Title
- read lines of file randomly java
- Category
- Java
- Title
- java empty array
- Category
- Java
- Title
- Enums injava
- Category
- Java
- Title
- create an empty array in java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- java date time
- Category
- Java
- Title
- loop collection android
- Category
- Java
- Title
- index of an array procesing
- Category
- Java
- Title
- java vector push_back
- Category
- Java
- Title
- how to change text size of textview with code in android studio
- Category
- Java
- Title
- leap year program in java
- Category
- Java
- Title
- difference between java and javascript
- Category
- Java
- Title
- 2 decimal places print format JAVA
- Category
- Java
- Title
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- Category
- Java
- Title
- java if
- Category
- Java
- Title
- split with multiple condition in java
- Category
- Java
- Title
- setting up javafx in eclipse
- Category
- Java
- Title
- how to declare list of object in java as constant
- Category
- Java
- Title
- java interface
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- string to double java
- Category
- Java
- Title
- add a value to a list java in java hashmap
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- strong password regular expression java
- Category
- Java
- Title
- how to get all the names of the files in a folder in java?
- Category
- Java
- Title
- how to add a list in a list java
- Category
- Java
- Title
- get file path java
- Category
- Java
- Title
- how to add objects in array java
- Category
- Java
- Title
- objectoutputstream exemple
- Category
- Java
- Title
- java array out of bounds
- Category
- Java
- Title
- casting java
- Category
- Java
- Title
- delete object java
- Category
- Java
- Title
- what is a float java
- Category
- Java
- Title
- computeifabsent hashmap java
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- reentrantreadwritelock java
- Category
- Java
- Title
- java define a generic class that produces
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- java stack push
- Category
- Java
- Title
- how to reverse a string in java
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- how to create an abstract class in java
- Category
- Java
- Title
- java swing dialog box
- Category
- Java
- Title
- java for each
- Category
- Java
- Title
- how do i print text in java
- Category
- Java
- Title
- java get environment variables
- Category
- Java
- Title
- read a file in java and store as integer array using buffered reader
- Category
- Java
- Title
- null pointer exception java
- Category
- Java
- Title
- java 8 collect multiple lists into single list
- Category
- Java
- Title
- how to set a windows background image tkinter
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- bootstrap button bigger
- Category
- Java
- Title
- java check if directory exists
- Category
- Java
- Title
- java thread
- Category
- Java
- Title
- hide element selenium
- Category
- Java
- Title
- sign flutter app android studio
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- java string regexp replace
- Category
- Java
- Title
- make recycler view non scrollable
- Category
- Java
- Title
- primitive and non primitive data types in java
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- init admob
- Category
- Java
- Title
- creating random color in java
- Category
- Java
- Title
- how to make javafx full screen default
- Category
- Java
- Title
- java program to display characters from a to z using loop
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- how to play an audio in java
- Category
- Java
- Title
- method overloading
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- D/NetworkSecurityConfig: No Network Security Config specified, using platform default
- Category
- Java
- Title
- how to open a text file in java
- Category
- Java
- Title
- nextchar in java
- Category
- Java
- Title
- check if value exists in hashset java
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- java for
- Category
- Java
- Title
- how to use for loop for array in java
- Category
- Java
- Title
- java loop
- Category
- Java
- Title
- java recursion
- Category
- Java
- Title
- java put a char array into a string
- Category
- Java
- Title
- how to limit double decimal places java
- Category
- Java
- Title
- rgb to hex java
- Category
- Java
- Title
- java decler variabel
- Category
- Java
- Title
- java execute jar from main
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- how to print hello world in java
- Category
- Java
- Title
- how to get length of integer in java
- Category
- Java
- Title
- java setroundingmode
- Category
- Java
- Title
- java output array lists to file
- Category
- Java
- Title
- java script removing first three indexes
- Category
- Java
- Title
- time conversion solution
- Category
- Java
- Title
- sending a excel in an attachment in email java
- Category
- Java
- Title
- java import text file into arraylist
- Category
- Java
- Title
- java 8 function supplier consumer
- Category
- Java
- Title
- how to substring in java
- Category
- Java
- Title
- reverse string using recursion java with explanation
- Category
- Java
- Title
- Java arraylist if you don't want to use add()
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- split method in java
- Category
- Java