Problems with FileImageOutputStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomad5000
    New Member
    • Sep 2006
    • 22

    #1

    Problems with FileImageOutputStream

    Hi I'm trying to write to a text file with the class FileImageOutput Stream but I can't manage to overwrite the file I'm writing to. So I tried to flush the Object with the flush() method but it still doesn't work. Here is my code:
    Code:
    import java.io.File;
    import javax.imageio.stream.FileImageInputStream;
    import javax.imageio.stream.FileImageOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    public class FileWriter{
    	public static void main(String[] args){
    		try{
    			File file = new File("test.txt");
    			FileImageOutputStream	fileWriter = new FileImageOutputStream(file);
    			for(int i=0;i<20;i++){
    				fileWriter.writeBytes("test this\n");
    			}
    			fileWriter.close();
    			FileImageOutputStream	fileWriter2 = new FileImageOutputStream(file);
    			fileWriter2.flush();
    			fileWriter2.writeBytes("test\n");
    		}
    		catch(Exception e){
    			System.out.println("the file could not be opened");
    		}
    	}
    }
    and here is the output to the test file
    test.txt

    Code:
    test
    this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    test this
    what I want the textfile to look like after running the programm is the following

    Code:
    test
Working...