展开全部
java通过InputStream读取和写入文件操作实32313133353236313431303231363533e59b9ee7ad9431333365643534例代码
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();