java.io.lnputstream,无法隐式转换类型'的System.IO.Stream'到'的java.io.InputStream“

I referred some similar questions on SO but none of them deals with IO.

I had used the same code in java when I used Eclipse. That time it worked.

But now I try to use this code in Mono for Android (C#), it doesn't work.

I'm trying to run this code to create an InputStream:

InputStream myInput =ctx.Assets.Open(DATABASE_NAME + ".db");

But it is giving me compile-time error : Cannot implicitly convert type 'System.IO.Stream' to 'Java.IO.InputStream'

There is a direct function to copy a file from assets to device memory but that requires source and destination path.

How do I get the source Path???

As I'm absolute beginner to Mono for Android, any help appreciated.

解决方案

Mono for Android translates some Java constructs into "equivalent" .NET constructs to ease code sharing between .NET-like platforms. As part of this, java.io.InputStream and java.io.OutputStream are mapped to System.IO.Stream, hence the compiler errors.

Is there anything you require that exists on InputStream that doesn't exist on System.IO.Stream?

There is a direct function to copy a file from assets to device memory but that requires source and destination path.

I have no idea what InputStream method you're referring to here. You can use Stream.CopyTo(Stream) to do that:

Stream asset = context.Assets.Open(DATABASE_NAME + ".db");

string dbPath = System.IO.Path.Combine(

System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),

"YourFile.xml");

using (var dest = System.IO.File.OpenWrite(destPath))

asset.CopyTo(dest);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值