java如何将一个InputStream写入文件?
1个回答
展开全部
java通过InputStream读取和写入文件操作实例代码
1. File to InputStream
File file = new File("file.xml");
InputStream inputStream = new FileInputStream(file);
2.InputStream to File
InputStream inputStream = new FileInputStream("file.xml");
OutputStream outputStream = new FileOutputStream("file-new.xml");
int bytesWritten = 0;
int byteCount = 0;
byte[] bytes = new byte[1024];
while ((byteCount = inputStream.read(bytes)) != -1)
{
outputStream.write(bytes, bytesWritten, byteCount);
bytesWritten += byteCount;
}
inputStream.close();
outputStream.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询