Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...