2011-08-18 154 views
2

我需要寫大量數據到磁盤,所以我用FileStream.openAsync()是否可以在FileStream中設置BufferSize?

this.file_stream = new FileStream(); 
this.file_stream.openAsync(fl, FileMode.WRITE); 

//Write large get from database 
while(i < 10240000) { 
    this.file_stream.write(bigDatas) 
    i = i + 1; 
} 

,然後應用程序被Linux kenkel(郵件副本從 'dmesg的')遇難:

終止進程4267 (MyFlex)總-VM:1282708kB,匿名-RSS:863176kB,文件RSS:756KB

那麼,有沒有什麼辦法來設置緩衝區大小的FileStream?

+1

這可能是有用的,即使它涉及閱讀不寫:http://stackoverflow.com/questions/2321951/as3-working-with-arbitrarily-large-files – altschuler

回答

0

您試圖執行一個循環10百萬次。

問題不在於FileStream的緩衝區。說感謝Linux停止執行您的應用程序,並避免您的系統爆炸。

你需要保存一個文件,當文件保存時,進入下一步,查看代碼,「writeFile」函數等待CLOSE事件再次執行。

import flash.filesystem.File; 
import flash.filesystem.FileMode; 
import flash.filesystem.FileStream; 
import flash.events.Event; 

var file:File; 
var stream:FileStream = new FileStream(); 

stream.addEventListener(Event.CLOSE, writeFile); 

var cont:uint = 0; 
//---I do not think that you need to run a code 10 million times (This code will save the file 10 times) 
var total:uint = 10; 

//---Write file in the Desktop in the folder "test" 
function writeFile(evt:Event = null){ 

    cont++; 

    if(cont == total + 1) { 

     stream.removeEventListener(Event.COMPLETE, writeFile); 

     trace("finish"); 

    }else{ 

     trace("write file number " + cont); 

     file = File.desktopDirectory.resolvePath("test/data" + cont); 

     stream.openAsync(file, FileMode.WRITE); 

     stream.writeByte(0xFF); 

     stream.close(); 

    } 

} 

//---Execute the function for first time 
writeFile(); 
相關問題