Java - How to read a string line per line

Java - How to read a string line per line

Java - How to read a string line per line

I am trying to find the tutorial for reading the String line per line. I have a String data, which contains many lines. What is the best way to read the big String line per line? Is there any API available in Java for this purpose?

Thanks

View Answers

February 26, 2013 at 8:09 AM

Hi,

The best way is to Read the data is to read it line by line. This way you can reduce the memory usage of the application and also make your application more scalable. You can use the BufferedReader or Scanner class provided by the Java API.

Using BufferedReader or Scanner class you can make your application more scalable. This way it can execute the application fast with low memory and CPU.

If you have big file you can also use the BufferedReader or Scanner class for reading the file line by line.

Following code might be used for reading the String line by line:

String[] lines = myString.split(System.getProperty("line.separator"));

Read more at:

Thanks


February 26, 2013 at 8:12 AM

Hi,

You may also use the Apache Commons IOUtils for this purpose.

Thanks









Related Tutorials/Questions & Answers:
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
java - read file line by line in Java
java - read file line by line in Java  Hi, how one can read a text... the details at How to read file line by line in Java?   What is the benefits... file in Java can be read line by line with the help of BufferedReader class
Advertisements
nio read file line by line
nio read file line by line  Is there any way to read file line by line using the Java nio package? How to use the nio classes to read file line... the BufferedReader class. Check the tutorial Java Read File Line by Line - Java
Making XY line chart with string and double axis
Making XY line chart with string and double axis  Good evening everybody So i'm trying to make a XYLine chart with JFreechart. The data comes from 2... into the dataset. The horizontal axis are going to be represented by a string (showing day
java line chart
java line chart  Hi, I want to draw a graphic in java line chart and ? searched the documents ?n the web. I found the example codes ?n your site (http://www.roseindia.net/chartgraphs/xyline-chart.shtml) and tr?ed ?n my
line length in java - Java Beginners
line length in java  Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enough dots so that the total line length is 30  Hi friend
objective c read file line by line
objective c read file line by line  Please explain how to read files in Objective C line by line
Line Graphs in java - Java Beginners
Line Graphs in java  Hi... I need to generate a graph by using the database values using java I know about the JFreeChart class... But by using... Chart { public static void main(String[] args) throws Exception { String
Multi line graph - Java Beginners
Multi line graph  Hi, I want a multi line graph on a single chart using jfree in java.... Can you please let me know the code... thanks... MultiLineChart extends ApplicationFrame { public MultiLineChart(final String title
Read file line by line in Java 8
Tutorial Java read file line by line - Java Tutorial How to read...Java 8 Read file - Reading file line by line in Java 8 Today  we... { public static void main(String[] args) { System.out.println("Java 8 Read
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
line graph
line graph  I have developed an application and in that i have to compare 2 reports using line graph from the data taken from ms access database?please help
Command line argument in java
Command line argument in java. In this section we are going to discuss about command line argument in java. Command line argument allow a user to pass... to the command line. It accept into the string argument of main method. Command
Removing Line Termination Characters from a String
Removing Line Termination Characters from a String... the string as output in the console, you will understand where the new line... symbol where the new line character was present in the string or text
Line Animation in Java
Line Animation in Java       In this example we are creating an animated line. The color of  line is changing alternatively. We use drawLine() to draw a line
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full DescriptionADS_TO_REPLACE_1
Java I/O From the Command Line
Java I/O From the Command Line In this section we will learn about the I/O from the command line in Java. Several times you can see that the programs runs after taking the input from the command line. Java also supports for the command
Java Get Last Line of File
Java Get Last Line of File     ... you in understanding Get Last Line of File in Java . For this we have a class... the text.txt present in  stream reader. We declare a String object name line
Compiling and Running Java program from command line
Compiling and Running Java program from command line - Video tutorial... of compiling and running java program from command line. We have also video... of the Compiling and Running Java program from command line: View more tutorials
divide the line in to two
divide the line in to two  In| this |example |we| are| creating |an |string| object| .We| initialize| this| string |object| as| "Rajesh Kumar"|.| We| are| taking| sub| string | In above mentioned line based on the tag i want
Draw Line in PowerPoint Presentation Using Java
Draw Line in PowerPoint Presentation Using Java       In this example we are going to create line in PowerPoint presentation using java. In this example we are going to make
character as command line arguments
character as command line arguments  public class testing { public static void main(String args[]) { char a; a=args[0]; System.out.println("character is:"+a); } } what will be the above program output
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java...(in)); readline() is used to read the next line. Example of Java Read File:ADS_TO_REPLACE_3
COMMAND LINE ARGUMENTS
COMMAND LINE ARGUMENTS  JAVA PROGRAM TO ACCEPT 5 COMMAND LINE ARGUMENTS AND FIND THE SUM OF THAT FIVE.ALSO FIND OUT LARGEST AMONG THAT 5   ... FindSumAndLargest{ public static void main(String[] args){ int max = Integer.MIN
Line Number Reader Example
; readLine() method is used to read the data line by line. LineNumberReader...(): This method is used to read the data line by line. Then returns the data... LineNumberReaderExample{ Line: 3: public static void main(String[] args) throws Exception
Java Command Line Input
Java Command Line Input  How to get input from command line in java ?   Hi please Find the code for inputting data from the command line... = new BufferedReader(new InputStreamReader(System.in)); String data
Command line arguments
Command line arguments  Please explain me what is the use of "command line arguments" and why we need to use
Line From code
Line From code  document.getElementById("demo").innerHTML=Date(); Please explain each and every word in this line
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart
JBoss Unix and Line Separator
JBoss Unix and Line Separator  Hi, I am trying to solve an critical problem. I have an application which write a batch file using the method println from the PrintWriter class from java api, this method uses the default line
sorting Line in c
sorting Line in c  Hi I need help with sorting line in programming c asking user to enter 1-10 characters and then sort them in lower case, alphabetical and ascending order. Any help will be appreciated! please help! void
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source selected from listbox and multiple targets selected from checkboxes. After submitting... multiple target. And each line should have dynamically link of other jsp page
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
Line Graph using JFreeChart
Line Graph using JFreeChart  I need to draw a line graph of the (no. of sales made on y axis) by a shop with (dates on x axis) using data from MySQL database and JFreeChart. DRIVER: com.mysql.jdbc.Driver URL: jdbc:mysql
dead line tomorrow...help
dead line tomorrow...help  1)write a program to convert double to int and viceversa using rmi(remote method invocation) 2)write a program to download a video file and run it on your client machine using rmi 3)fibonacci
What is wrong with this line
What is wrong with this line  What is wrong with this line JOptionPane.showMessageDialog(null? for Using Lewandowski's Savings pgrm!"); from if (input.equals("exit") || input.equals("Exit")) { JOptionPane.showMessageDialog
On line examination project
On line examination project  Hi, I am doing project in jsp,nam eis online examination project. I am facing some problems. In my database several questions. There should be one question in one page. And 2 button previous and next
Java read file line by line - Java Tutorial
C:\nisha>javac ReadFile.java C:\nisha>java... input line by line with an appropriate BufferedReader.ADS_TO_REPLACE_1...;File Line By Line   while ((strLine = 
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line.../java/beginners/cmnd-line-arguments.shtml Thanks
Retriving data from MYSQL without line break using java
Retriving data from MYSQL without line break using java  get data without line breaking from mysql table (i.e data stored as mediumtext )using java
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line... take any number of command-line arguments which may be necessary for the program
What is regular expression beginning of line ?
What is regular expression beginning of line ?  Hi, I one of my Java program I have to write a program to find the beginning of a line... this will be helpful for you. http://www.roseindia.net/java/string-examples/string
Java program to get the Command Line Arguments
Java program to get the Command Line Arguments       In java we can get the command  line... program we can use the string array variable args for holding command line
Different Line Styles
Different Line Styles       This section shows you different styles of Line. To show different styles of line, we have used BasicStroke class. The class BasicStroke
command line arguments - Java Beginners
command line arguments  how can i findout the minimum and maximum no's at the command prompt if i give some values?????????  hi friend.... import java.util.*; public class MaxMin { public static void main(String[] args
What is command line argument in Java
in Java and how one can use it to create a program in Java? Can you post any example of command line argument program in Java?? It will be really helpful... of arguments from the command line. Arguments are passed as a string array
PHP GD line graph
($im,3,10,$height-20,'Line Graph by: Roseindia Technologies',$red);ADS_TO_REPLACE_12
Adding Line to JTree
Adding Line to JTree        In this section, you will learn to create JTree along with a dividing Line. Here the tree gets  divided into two parts separated by a line. Both

Ads