I've started by creating a Main class in which I read the file to a String. But then I'm not sure how to parse it, if I should use regular expressions or just simply doing it the "hard" way. If you have tried something and facing issues, you can post it here. Should be quite straight forward unless you have some complex requirement. Use a file reader to read each line and split based on the separator to a list and then use whatever data is needed from the list.
Add a comment. Active Oldest Votes. Read in the text file line by line and then do an action based on that line. Luo Sen Luo Sen 97 6 6 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE. The choice of using a Scanner or BufferedReader or Files to read file depends on your project requirements.
For example, if you are just logging the file, you can use Files and BufferedReader. If you are looking to parse the file based on a delimiter, you should use Scanner class.
We can use this to read text file in java. Can you please give an example. The above line will gives you all your file data as byte array. So, if you want all file data as String, not need to add it. Your email address will not be published.
Prev How to open a File in Java. Next Scanner Class in Java. Pankaj I love Open Source technologies and writing about my experience about them is my passion.
Follow Author. Comments Sami says:. August 4, at am. Related Articles. Table of Contents. Improve Article. Save Article. Like Article. BufferedReader br.
String st;. Next Split String method in Java with examples. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert.
Writing code in comment? Please use ide. Load Comments. What's New.
0コメント