Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - getResourceAsStream doesn't work ( Eclipse )

I try to extract a file which is attached in my "src" folder.

So I wanted to get the Inputstream from the file and write it into for example c:/file.txt

my code:

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

The Error:

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

like image 882
Aurus Avatar asked Nov 24 '25 02:11

Aurus


2 Answers

Remove this import

import org.omg.CORBA.portable.InputStream;

from your class, and add

import java.io.InputStream
like image 63
linski Avatar answered Nov 25 '25 16:11

linski


You imported the wrong InputStream.

Try importing java.io.InputStream instead of org.omg.CORBA.portable.InputStream.

like image 42
Jean Logeart Avatar answered Nov 25 '25 15:11

Jean Logeart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!