2011-05-31 210 views
-2

如何將以下Android代碼轉換爲MonoAndroid代碼?將Android代碼轉換爲MonoAndroid代碼

//Open your local db as the input stream 
    InputStream myInput = myContext.getAssets().open(DB_NAME); 

    // Path to the just created empty db 
    String outFileName = DB_PATH + DB_NAME; 

    //Open the empty db as the output stream 
    OutputStream myOutput = new FileOutputStream(outFileName); 

    //transfer bytes from the inputfile to the outputfile 
    byte[] buffer = new byte[1024]; 
    int length; 
    while ((length = myInput.read(buffer))>0){ 
     myOutput.write(buffer, 0, length); 
    } 

    //Close the streams 
    myOutput.flush(); 
    myOutput.close(); 
    myInput.close(); 

是否有任何特殊的dll引用或使用語句?

感謝

回答

0

後襬弄周圍的天徒勞的google搜索, 'Assets.Open(@ 「test.db的」)' 是關鍵:

//Open your local db as the input stream 
    Stream myInput = Assets.Open(@"test.db"); 
    string outFileName = Path.Combine(System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), "test.db"); 
     //Open the empty db as the output stream 
     Stream myOutput = new FileStream(outFileName,FileMode.OpenOrCreate); 
    byte[] buffer = new byte[1024]; 
    int b = buffer.Length; 
    int length; 
    while ((length = myInput.Read(buffer,0,b))>0){ 
     myOutput.Write(buffer, 0, length); 
    } 
    //Close the streams 
    myOutput.Flush(); 
    myOutput.Close(); 
    myInput.Close(); 
}