aspose file tools*
The moose likes I/O and Streams and the fly likes Reading first 10 lines from a file and writing it into another file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading first 10 lines from a file and writing it into another file" Watch "Reading first 10 lines from a file and writing it into another file" New topic
Author

Reading first 10 lines from a file and writing it into another file

Not mohammed
Greenhorn

Joined: Apr 05, 2012
Posts: 1
Hi,

I want to read first 10 lines of a text file and then write the same into a new file:
Below is the code which I tried, but ain't able to write anything.

Your help will be greatly appreciated.

in my main method, I have:



[Update: Added code tags (read UseCodeTags) ]
Andi Eska
Greenhorn

Joined: Jun 20, 2003
Posts: 14

Not mohammed wrote:Hi,

I want to read first 10 lines of a text file and then write the same into a new file:



You'll have to call flush() of your writer additionally it is recomended to close all your streams.
The call to flush is optional when you call close() on a Writer.
In Java 7 you can use the Autocloseable feature i.e. you don't have to call the close method explicitly.

A working example looks something like

Rajasekhar Karanam
Greenhorn

Joined: Sep 18, 2011
Posts: 15

Here is a simple solution for your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading first 10 lines from a file and writing it into another file