• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ]
 
Greenhorn
Posts: 14
Eclipse IDE VI Editor BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 16
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a simple solution for your problem.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic