【问题标题】:Java - getResourceAsStream doesn't work ( Eclipse )Java - getResourceAsStream 不起作用(Eclipse)
【发布时间】:2012-10-05 04:25:19
【问题描述】:
我尝试提取附加在“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();
错误:
类型不匹配:Eclipse 无法从 java.io.InputStream 转换为 org.omg.CORBA.portable.InputStream
【问题讨论】:
标签:
java
inputstream
outputstream
【解决方案1】:
删除此导入
import org.omg.CORBA.portable.InputStream;
来自你的班级,然后添加
import java.io.InputStream
【解决方案2】:
您是否导入了:- org.omg.CORBA.portable.InputStream 而不是 java.io.InputStream?
检查一下,如果你有第一个导入,用后面的替换它。
【解决方案3】:
您导入了错误的类org.omg.CORBA.portable.InputStream。正确的班级是java.io.InputStream。
【解决方案4】:
删除org.omg.CORBA.portable.InputStream的导入,改成java.io.InputStream
【解决方案5】:
你输入了错误的InputStream。
尝试导入java.io.InputStream 而不是org.omg.CORBA.portable.InputStream。