Re: Create a file from a binary stream

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Lars-Inge Tønnessen [VJ# MVP] (http://emailme.larsinge.com)
Date: 12/27/04


Date: Mon, 27 Dec 2004 19:44:10 +0100


Please try a binary serializable formater.

Somthing like this:

/** @attribute System.SerializableAttribute() */
public class test implements java.io.Serializable
{
 public int number = 0;
}

public class Class1
{
 public Class1()
 {
  try
  {
   test one = new test();
   one.number = 10;

   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formater =
    new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

   System.IO.Stream YourStream = new System.IO.FileStream( "path.bin",
    System.IO.FileMode.Create,
    System.IO.FileAccess.Write,
    System.IO.FileShare.None);

   formater.Serialize( YourStream, one );
  }
  catch ( Exception e )
  {
   System.Console.WriteLine( e.getMessage() );
  }

 }

 /** @attribute System.STAThread() */
 public static void main(String[] args)
 {
  new Class1();
 }
}

Regards,
Lars-Inge Tønnessen



Relevant Pages