• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Writing and reading from a file.

 
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
 
Bartender
Posts: 9559
12
Mac OS X Linux 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.
 
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!