Java - How to read a string line per line

Ads
 

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

Ads









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
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
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
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
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
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
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
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
Java I/O From the Command Line
() This method is used to read a line of text from the console. readLine(String...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
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... line. Example of Java Read File: package FileHandling; import
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full Description
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
Read file line by line in Java 8
examples of reading files in Java: Java Read File Line by Line - Java 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
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... command line: View more tutorials on Java
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
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
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
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
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
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
Line From code
Line From code  document.getElementById("demo").innerHTML=Date(); Please explain each and every word in this line
Command line arguments
Command line arguments  Please explain me what is the use of "command line arguments" and why we need to use
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
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
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
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file... having less amount of memory. In the example of Java Read line by line below... of BufferedReader class that is used to read a complete line and return string
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

Ads