Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

add text to a .txt file

 
Mike Flynn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to write a small program that will allow me to read a txt file and append text to the end and beginning of each line.
cheers in advance
 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tryiing using this method
public void write(String s, int off, int len)
It is part of the bufferedwriter class
take a look at the javadocs
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mike! It's always good to see new first posts!

What have you tried and what's not working for you? If you have some code fragments (keep em small, and use the "code" button in the Ranch editor) we can look them over and see what's going on.
 
Mike Flynn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just starting out java, mainly programme mainframe(procedural) but trying hard, I have large sql queries for payments done in query analyser but want a program to append the text 'query.append("' at the beginning of a line and of course ' ");' to the end of a line.

 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code doesn't compile. I think you have the "char" data type, which is a single character, confused with either an array of char's or a String object. You should get familiar with the Java Tutorial. Plenty of helpful information, like what Data Types are available and how to perform IO.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this as a first stab?Caveat: if the read line contains any " characters, you'll need to escape them by preceding each one with a backslash (\). But it's time for bed so I'll leave that for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!