Thread: print line
View Single Post
  #1 (permalink)  
Old 01-24-2008, 04:26 PM
kazitula kazitula is offline
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); } } }
Reply With Quote
Sponsored Links