我试图将inputstream(从邮递员那里得到的表单数据)内容写到文件中,以便可以做进一步的操作,例如读取文件的每一行,但始终将转换后的文件的大小设为零,并且没有数据。尝试以下两种方式
public File isFileFormatValid(IMultipartBody fileHeaderData, InputStream fileStream, boolean overwrite)
throws Exception {
File tempFile = null;
String fileName = getFileNameFromMultipartBody(fileHeaderData);//returns sample.csv
tempFile = new File("C:\\temp", fileName);
FileUtils.copyInputStreamToFile(fileStream, tempFile);
//getting no data at c:\temp\Sample.csv
//方式2
FileOutputStream fos = new FileOutputStream(tempFile);
byte[] buffer = new byte[8 * 1024];
int read = 0;
while ((read = fileStream.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
// Closing all open resources
fos.close();