场景:JDK8 将上传的文件,保存到服务器
Java读写文件操作:
MultipartFile file
InputStream inputStream = file.getInputStream();
private void saveOldFile(String uid,String fileName,InputStream inputStream){ String filePath = getFilePath() + "/" + uid +fileName; BufferedReader reader = null; BufferedWriter writer = null; try { File file = new File(filePath); reader = new BufferedReader(new InputStreamReader(inputStream)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); String lineText = null; while ((lineText = reader.readLine()) != null){ writer.write(lineText+FILE_CONTENT_SPLIT_MARK); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { try { writer.close(); reader.close(); } catch (IOException e) { e.printStackTrace(); } } }
原文地址:https://www.cnblogs.com/sxdcgaq8080/p/10936334.html
时间: 2024-10-06 02:41:50