Java - getResourceAsStream不起作用(Eclipse)

时间:2012-10-15 08:04:48

标签: java inputstream outputstream

我尝试提取一个附在我的“src”文件夹中的文件。

所以我想从文件中获取Inputstream并将其写入例如c:/file.txt

我的代码:

InputStream is = Main.class.getResourceAsStream("test.txt");

OutputStream os = new FileOutputStream("c:/file.txt");
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0) {
    os.write(buffer, 0, length);
}
os.close();
is.close();

错误:

" Type mismatch: Eclipse cannot convert from java.io.InputStream to 
                 org.omg.CORBA.portable.InputStream "

谢谢

5 个答案:

答案 0 :(得分:6)

删除此导入

import org.omg.CORBA.portable.InputStream;
来自你班级的

,然后添加

import java.io.InputStream

答案 1 :(得分:1)

您导入了错误的InputStream

尝试导入java.io.InputStream而不是org.omg.CORBA.portable.InputStream

答案 2 :(得分:1)

删除org.omg.CORBA.portable.InputStream的导入并将其更改为java.io.InputStream

答案 3 :(得分:1)

您导入了错误的班级org.omg.CORBA.portable.InputStream。正确的班级是java.io.InputStream

答案 4 :(得分:1)

您是否已导入: - org.omg.CORBA.portable.InputStream而不是java.io.InputStream

检查一下,如果您有第一次导入,请将其替换为以后的导入。

相关问题