Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read from text ouput ascii values

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
I have to write a simple Java program using file input and ouput. It has to read from a text file. This is how I did that:

Code:
try
{
   BufferedReader brInput = new BufferedReader(new InputStreamReader(System.in));
   String strInFileName = brInput.readLine();
   File fInput = new File(strInFileName);
   RandomAccessFile rafIn = new RandomAccessFile(fInput, "r");
...
...

That works fine but how do I write the ascii values to another file? Whenever I try to do it, it just writes the characters to the other file.

Thanks for the help.

Wallace
 
Use the FileInputStream and FileOutputStream instead of RandomAccessFile.

Code:
File fInput = new File(strInFileName);
FileInputStream fis = ...
FileOutputStream fos = ...
byte[] buf = new byte[(int)fInput.length()];
fis.read(buf);
fos.write(buf);
//flush & close streams

--------------------------------------------------
Free Database Connection Pooling Software
 
PS, this forum is for J2EE, the standard Java forum is forum269 .

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top