Corrupted Output file

From: Wade (wade_at_wadesmart.com)
Date: 11/04/04

  • Next message: Bjorn Abelli: "Re: Starting UML"
    Date: 4 Nov 2004 13:22:36 -0800
    
    

    11042004 1509 GMT-6

    One of the exercises in my Java text is a simple output file that
    creates a gif image. I had written this file before but after
    reinstalling Eclipse Im having trouble with this output being
    corrupted.

    Here is the code:

    import java.io.*;

    public class WriteBytes {

    public static void main(String[] args) {
    int[] data = { 71, 73, 70, 56, 56, 97, 15, 0, 15, 0, 128, 0, 0, 255,
    255, 255, 0, 0, 0, 44, 0, 0, 0, 0, 15, 0, 15, 0, 0, 2, 33, 32, 127,
    161, 200, 185, 205, 84, 128, 241, 81, 35, 175, 155, 26, 228, 254, 105,
    33, 102, 121, 165, 201, 145, 169, 154, 142, 172, 116, 162, 240, 90,
    197, 5, 0, 59 };
    try {
    //FileOutputStream file = new
    FileOutputStream("C:/WebDev/eclipse/workspace/Week3/Day15/pic.gif");
    FileOutputStream file = new FileOutputStream("pic.gif");

    for (int i = 0; i < data.length; i++)
    file.write(data[i]);
    file.close();
    } catch (IOException e) {
    System.out.println("Error - - " + e.toString());
    }
    }
    }

    The output is the letter "J". Im image comes out as pic.gif however,
    its unreadble by any imaging program.

    Wade


  • Next message: Bjorn Abelli: "Re: Starting UML"