开发者

Convert Android Code to MonoAndroid Code

How do I convert the following Android code to MonoAndroid code?

//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();

And are there any special dll references or using statements?

Thanks


After days of fiddling around and futile googling, 'Assets.Open(@"test.db")' was the key:

    //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();
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜