• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Update the character on file writing.

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have requirement to copy content from one file to another. So is my below code. But the additional requirement is that the second character in every line should be checked and changed to character 'X'. Please let me know how can this be checked.


 
Sheriff
Posts: 22649
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eshwar Prasad wrote:


That's going to give you problems. read moves the file's internal pointer forward, so some data will be read but never used.

You mention lines. Then you shouldn't read byte[] per byte[]. Instead, switch to something that knows how to read lines; a BufferedReader around a FileReader perhaps. (Don't forget to switch from FileOutputStream to FileWriter as well.)

Then read the file line by line, modify the line (warning: what if the line has 0 or 1 characters?) and write it to the file (using FileWriter). Don't forget to add new line breaks yourself, because most (all?) line reading classes strip away the line breaks.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic