Results 1 to 3 of 3
Thread: print line
- 01-24-2008, 02:26 PM #1
Member
- Join Date
- Oct 2007
- Posts
- 10
- Rep Power
- 0
print line
hi
how can i print a sentence in different lines? like... "this is for the test of java"
so if i want to print this in the following way...
this
is
for
the
test
of
java
here is my code...
Java Code:import java.io.*; public class FileReading { // Main method public static void main (String args[]) { // Stream to read file try { // Open an input stream FileInputStream fileinput = new FileInputStream ("c:\\readfile.txt"); // Read a line of text // System.out.println( new DataInputStream(fileinput).readLine() ); DataInputStream in = new DataInputStream(fileinput); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println (strLine); } // Close our input stream fileinput.close(); } // Catches any error conditions catch (IOException e) { System.err.println ("Unable to read from file"); System.exit(-1); } } }
- 01-24-2008, 05:10 PM #2
Well, basically, unless there is a method in API that I am unaware of ... you should treat the whitespace character differently than it is normally processed. For example, when you read the character, treat it as a newline. You probably can guess this... but if do you know this, you should be able to come with the way to do it. Also, you read in the data line by line.. so maybe you should use... read() or something like... readChar()....
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-26-2008, 02:05 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
how to print output on same line in 'while loop'?
By acidblue in forum New To JavaReplies: 5Last Post: 12-13-2007, 02:30 AM -
Print Area
By Riftwalker in forum Advanced JavaReplies: 0Last Post: 11-28-2007, 07:28 PM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
Print XML tag
By DonCash in forum XMLReplies: 2Last Post: 08-07-2007, 06:02 PM -
Print A Pdf
By Jack in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 05:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks