javajava 读写文件
Posted sxdcgaq8080
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javajava 读写文件相关的知识,希望对你有一定的参考价值。
场景: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(); } } }
以上是关于javajava 读写文件的主要内容,如果未能解决你的问题,请参考以下文章
javajava 中 byte[]FileInputStream 互相转换