Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...