Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008, 04:26 PM
Member
 
Join Date: Oct 2007
Posts: 10
kazitula is on a distinguished road
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...

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); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 07:10 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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()....
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-26-2008, 04:05 PM
Member
 
Join Date: Jan 2008
Posts: 6
sabbirhs is on a distinguished road
there are some string fuction which take care about spaces and \n, i think youshould look at those. other then you can read string by string rather then line by line.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to print output on same line in 'while loop'? acidblue New To Java 5 12-13-2007 04:30 AM
Print Area Riftwalker Advanced Java 0 11-28-2007 09:28 PM
Reading in data from file line by line bluekswing New To Java 1 10-02-2007 02:19 AM
Print XML tag DonCash XML 2 08-07-2007 08:02 PM
Print A Pdf Jack Advanced Java 2 07-02-2007 07:40 AM


All times are GMT +3. The time now is 07:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org