# How to write an image to application directory using AIR?

**URL:** https://forum.kirupa.com/t/how-to-write-an-image-to-application-directory-using-air/324205
**Category:** flash
**Created:** [August 8, 2011, 6:23pm UTC](https://forum.kirupa.com/t/how-to-write-an-image-to-application-directory-using-air/324205 "2011-08-08T18:23:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sindrom](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sindrom](https://forum.kirupa.com/u/sindrom)
#### Post date: [August 8, 2011, 6:23pm UTC](https://forum.kirupa.com/t/how-to-write-an-image-to-application-directory-using-air/324205/1 "2011-08-08T18:23:31Z")

</div>

I’m trying to save an image to the application directory by opening a file stream and write the bytes from a bitmap data. I added some events listeners for testing the file stream process but I don’t receive any response event. Can you take a look over my code and tell me where might be the problem.

```auto
  
            var bd:BitmapData = new BitmapData(CANVAS_WIDTH, CANVAS_HEIGHT);
            bd.draw(currentDrawing);
[LEFT] var jpgEncoder:JPGEncoder = new JPGEncoder(100);
            var ba:ByteArray = jpgEncoder.encode(bd);
            
            var newImage:File = File.applicationDirectory.resolvePath("images/test.jpg");  
            var fileStream:FileStream = new FileStream();  
            fileStream.open(newImage, FileMode.UPDATE);  
            fileStream.writeBytes(ba); 
            fileStream.addEventListener(Event.CLOSE, fileClosed);  
            fileStream.addEventListener(Event.COMPLETE, fileComplete);  
            fileStream.addEventListener(IOErrorEvent.IO_ERROR, fileError); 
            fileStream.close();
            
            
            function fileClosed(event:Event):void {  
                outputText.text = "close";
            }
            
            function fileComplete(event:Event):void {  
                outputText.text = "complete";
            } 
            function fileError(event:IOErrorEvent):void {  
                outputText.text = "error"; 
            } [/LEFT]

```
