Created
May 7, 2022 17:31
-
-
Save gabrieleboccarusso/7d526818828b3d864ef57ad29085bffe to your computer and use it in GitHub Desktop.
This gist contains the base snippet to read files in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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