将FileOutputStream转换为FileInputStream的最简单方法是什么(一段代码会很棒)?
Tho*_*mas 16
这可能对您有所帮助:
http://ostermiller.org/convert_java_outputstream_inputstream.html
本文提到了3种可能性:
仅供参考,反过来做(输入到输出):
使用Apache Commons IO的简单解决方案是:
IOUtils.copyLarge(InputStream, OutputStream)
Run Code Online (Sandbox Code Playgroud)
或者如果您只想复制文件:
FileUtils.copyFile(inFile,outFile);
Run Code Online (Sandbox Code Playgroud)
如果您不想使用Apache Commons IO,请执行以下copyLarge方法:
public static long copyLarge(InputStream input, OutputStream output) throws IOException
{
byte[] buffer = new byte[4096];
long count = 0L;
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33358 次 |
| 最近记录: |