[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: File IO troubles...



 

	-----Original Message----- 
	From: Lance England 
	Sent: Thu 9/13/2001 12:52 PM 
	To: Deron Pardue 
	Cc: 
	Subject: RE: File IO troubles...
	
	
	I wish I knew the specific answer to this, but I don't.
	Have you tried ObjectOutputStream.writeUTF(String) ? It's method
description "Primitive data write of this String in UTF format". BTW, an
easier class to use for text-file writing is FileWriter.
	 
	Lance
	 
	-----Original Message----- 
	From: Deron Pardue 
	Sent: Thu 9/13/2001 12:06 PM 
	To: ajug-members@www.ajug.org 
	Cc: 
	Subject: File IO troubles...
	
	

		I'm having trouble writing a text file.  My makeFile
method is listed below.  The problem is that I'm getting some strange
characters and some null bytes at the beginning of the file as well as
about every 1k characters.  I don't have this problem when I write to
the console.  Any clues why my file io is adding more stuff?   Even by
creating the File object and not writing anything to it I get 4 null
bytes at the beginning of the file.   
		 
		Thanks!
		 
		Deron Pardue
		 
		****************************BEGIN
CODE********************************
		public void makeFile(StringBuffer sb, String title) 
		{
		     ObjectOutputStream output;
		     File filename = new File("c:\\" + title);
		 
		     try
		     {
		          output = new ObjectOutputStream(new
FileOutputStream(filename));
		          String s = sb.toString();
		  
		          byte ab[] = new byte[s.length()];
		          ab = s.getBytes();
		 
		          output.write(ab);
		          output.close();
		     }
		     catch (IOException e)
		     {
		          System.out.println("Error writing file " +
title + ":\n" + e);
		          System.exit(0);
		     }
		}
		****************************END
CODE********************************