The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Java I/O

Posted by Sanjay Ambardar on January 07, 2001 at 11:28 PM

I am writing the following programme to create a log file and write to it.

import java.util.*;
import java.io.*;

public class testOStream{

public static void main(String args[]){


try{
FileOutputStream fp = new FileOutputStream("Test.log",true);
ObjectOutputStream myStream = new ObjectOutputStream(fp);
String s = "Test";
myStream.writeObject(s);
myStream.flush();
myStream.close();
}catch(FileNotFoundException e){
System.out.println("Cannot be done");
}catch(IOException e){System.out.println("IOException");}
}

}

The output i am getting in the file Test.log is as follows
�� t Test

Can anyone please help me in why I am getting the junk characters in my log file besides the desired string!!






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us