Results 1 to 4 of 4
Thread: How to print an input file?
- 09-17-2012, 01:17 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
How to print an input file?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TestBookCollection {
public static void main(String args[]){
File books = new File ("C:\\books.txt");
System.out.println(books);
}
}
Output: C:\books.txt
I know that it is input correctly but how do I get the content within the actual file to print?Last edited by Norm; 09-17-2012 at 02:43 AM. Reason: Not Advanced. Moved to New
- 09-17-2012, 02:41 AM #2
Re: How to print an input file?
You need to read the lines from the file so you can print them.how do I get the content within the actual file
The Scanner class is easy to use for text files. Define an instance of Scanner with the File and use its method to read the lines from the file.If you don't understand my response, don't ignore it, ask a question.
- 09-17-2012, 06:28 AM #3
Re: How to print an input file?
Why do they call it rush hour when nothing moves? - Robin Williams
- 09-17-2012, 08:38 AM #4
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
Re: How to print an input file?
----------------------------------------------------------------------------
Initially, read the file and contents'
----------------------------------------------------------------------------
'
'Java Code:FileReader fx=new FileReader("D:/output.txt"); BufferedReader bx=new BufferedReader(fx);
----------------------------------------------------------------------------
Declare a String and put contents in String
----------------------------------------------------------------------------
'
'Java Code:String holdcontents; holdcontents=bx.readLine();
----------------------------------------------------------------------------
Display the String'
----------------------------------------------------------------------------
'
'Java Code:System.out.print(holdcontents);
Similar Threads
-
Chat Server won't print out what it's supposed to with certain input.
By Wnt2bsleepin in forum New To JavaReplies: 2Last Post: 04-26-2012, 08:05 PM -
Print Parts Of An Array [User Input]
By PrimalScientist in forum New To JavaReplies: 22Last Post: 08-30-2011, 11:09 AM -
to print first and last number from a set of input numbers
By 95673641 in forum New To JavaReplies: 12Last Post: 03-28-2011, 09:30 PM -
About how to just print last 20 words from a input file
By Holic in forum New To JavaReplies: 3Last Post: 02-13-2011, 08:54 PM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks