File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Not mohammed
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
BSD Eclipse IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a simple solution for your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic