Skip to content

Instantly share code, notes, and snippets.

@gabrieleboccarusso
Created May 7, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrieleboccarusso/7d526818828b3d864ef57ad29085bffe to your computer and use it in GitHub Desktop.
Save gabrieleboccarusso/7d526818828b3d864ef57ad29085bffe to your computer and use it in GitHub Desktop.
This gist contains the base snippet to read files in java
import java.nio.file.Paths;
import java.util.Scanner;
public class ReadFile {
public static void main(String[] args) {
try (Scanner fileData = new Scanner(Paths.get("file.ext"))) {
while (fileData.hasNextLine()) {
current = fileData.nextLine();
if(!current.equals("")) {
// have fun
}
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment