简体   繁体   中英

How to convert InputStream to FileStream?

I want convert InputStream to FileStream on Android

Process process = Runtime.getRuntime().exec(cmd);
InputStream stdout = process.getInputStream();
FileInputStream fis = (FileInputStream)stdout;
FileDescriptor fd = fis.getFD();

"cmd" is stream command. Is it impossible? If possible, how can I fix it?

Use ClassLoader#getResource() instead.

URL resource = classLoader.getResource("Resource_Name");
File file = new File(resource.toURI());
FileInputStream input = new FileInputStream(file);

That said, I really don't see any benefit of doing so, or it must be required by a poor helper class/method which requires FileInputStream instead of InputStream. If you can, just use InputStream instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM