无法隐式转换类型'的System.IO.Stream'到'的java.io.InputStream“ [英] Cannot implicitly convert type 'System.IO.Stream' to 'Java.IO.InputStream'

查看:1281
本文介绍了无法隐式转换类型'的System.IO.Stream'到'的java.io.InputStream“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提到了一些类似的问题在左右,但他们没有处理 IO

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

我用同样的code在Java中,当我用的Eclipse 。这一次,它的工作。

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

但现在我尝试使用这个code。在单声道Android版(C#),这是行不通的。

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

我试图运行此code创建一个的InputStream

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

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

但它给我编译时错误:无法隐式转换类型'的System.IO.Stream'到'的java.io.InputStream

有一个直接的函数从资源文件复制到设备内存,但需要的源和目标路径。

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

如何获得源路径???

我敢绝对的初学者单声道Android版任何帮助AP preciated。

推荐答案

单声道为Android翻译一些Java构建成相当于.NET结构,以缓解.NET类平台之间code共享。作为其中的一部分,的java.io.InputStream 的java.io.OutputStream 映射到的System.IO.Stream ,所以编译器错误。

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.

你有什么需要存在于的InputStream 不上的System.IO.Stream 存在吗?

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.

我不知道的InputStream 方法,你指的是在这里。您可以使用 Stream.CopyTo(流)来做到这一点:

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

这篇关于无法隐式转换类型'的System.IO.Stream'到'的java.io.InputStream“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆