• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing and reading from a file.  RSS feed

 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Does anyone know how to write to and read from a file using a character encoding is 8 bit US ASCII.

Any code would be rather helpful. I am using a RandomAccessFile to read from and write to the file.

Thanks a lot
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RandomAccessFile writes binary files, not character based files. Have a look at the Java Tutorial chapter on IO for the basics, but you should probably be using a Reader/Writer combination.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean 7 bit ASCII? Never heard of 8 bit. If you are using the
current version of Java, PrintWriter has some new convenience constructors,
one, for example, takes a file and a charset name and constructs the
BufferedWriter, OutputStreamWriter and FileOutputStream for you.
In the other direction, you still have line up your ducks in a row,
but check out java.util.Scanner if you are reading and parsing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!