如何将FileInputStream转换为InputStream? [关闭]

问题

我只想将aFileInputStream转换为anInputStream,我该怎么做?

例如

FileInputStream fis = new FileInputStream("c://filename");
InputStream is = ?; 
fis.close();

#1 热门回答(127 赞)

InputStream is;

try {
    is = new FileInputStream("c://filename");

    is.close(); 
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

return is;

#2 热门回答(49 赞)

InputStream is = new FileInputStream("c://filename");
return is;

#3 热门回答(34 赞)

FileInputStreamisan inputStream。

FileInputStream fis = new FileInputStream("c://filename");
InputStream is = fis;
fis.close();  
return is;

当然,这不会做你想要它做的;你返回的流已经关闭。只需返回FileInputStream并完成它。调用代码应该关闭它。