Home Answers Viewqa Java-Beginners Java - How to read a string line per line

 
 


Java Coder
Java - How to read a string line per line
2 Answer(s)      2 months and 22 days ago
Posted in : Java Beginners

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 Pages:
Line Number Reader Example
; readLine() method is used to read the data line by line. LineNumberReader... is used to read the data line by line. Then returns the data of a line...:\convert\rajesh\completed>java LineNumberReaderExample Line: 1: import java.io.
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
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
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... in  stream reader. We declare a String object name line using new string
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
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
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
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full Description
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 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
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
writing a text into text file at particular line number
.. after line number four my text will display in text file using java program  ... static void main(String[] args) { String line...writing a text into text file at particular line number   Hi, thanks
writing a text into text file at particular line number
.. after line number four my text will display in text file using java program  ... static void main(String[] args) { String line...writing a text into text file at particular line number   Hi, thanks
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
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
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
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 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
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
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
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
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
Command line arguments
Java application can accept any number of arguments directly from the command line. The user can enter command-line arguments when invoking the application. When running the java program from java command, the arguments are provided
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
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
Read data again - Java Beginners
= DriverManager.getConnection("jdbc:odbc:hyt","root","suprax"); //Read File Line By Line...Read data again  sir, i still hav a problem,first your code.... Thank's try{ // Open the file that is the first // command line parameter
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
Read data again - Java Beginners
","root","suprax"); //Read File Line By Line while ((strLine = br.readLine..."); //Read File Line By Line while ((strLine = br.readLine()) != null...Read data again  OK my problem some like my first question.First i
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
JFreechart multi line chart help in JSP
JFreechart multi line chart help in JSP  Hi, I am am looking for and help in getting multi line chart with Jfree chart, i had manage to write a singe line chart but i need multy line can you please help. <%@page
C file read example
C file read example       This section demonstrates you to read a line from the file. You can see in the given example, we prompt the user to enter the name of the file to read
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
Break a Line for text layout
Break a Line for text layout   ... to break a line. To break down the text into lines, the class LineBreakMeasurer is used. The class Hashtable maps keys to values. A string is defined
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
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
Formatting number as per specific locale in java
Formatting number as per specific locale in java  Hi, I am trying to print the number as per locale. I tried below, but it still prints in English locale. public class loctest { public static void main(String[] args
Command line arguments
Command line arguments  Please explain me what is the use of "command line arguments" and why we need to use
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
Read Issue itext
In variable whole page data there... so i want to read data line by line so is der any way to read line by line data using itext so dat i can process it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
Read Issue itext
In variable whole page data there... so i want to read data line by line so is der any way to read line by line data using itext so dat i can process it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
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
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
Read page from Web server
Java NotesRead page from Web server The Java io package provides... http://www.yahoo.com using our java program and then saving on to our hard disk in a file. So, with the hop of java program you can download the HTML pages
Reverse String
: In the example given below, we are taking a command line argument and storing it in a string... Reverse String       In this example we are demonstrating the command line argument and displaying
Line by Line reading from a file using Scanner Class
In this section, you will get to know about reading line by line a text file using java.util.Scanner class

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.