根据内容生成文件
/*** 根据内容生本文件** @param filePath 本地路径* @param scriptContent 内容* @author YangYudi* @date 2021/1/8 17:16*/public static void writerFile(String filePath, String scriptContent) {//生成脚本 false表示不追加try (Writer writer = new FileWriter(filePath, false);BufferedWriter bufferedWriter = new BufferedWriter(writer)) {bufferedWriter.write(scriptContent);bufferedWriter.flush();writer.flush();} catch (IOException e) {log.error(e.getMessage());}}
根据输入流生成文件
public void inputStreamToFile(InputStream inputStream) {try {//新建文件File file = new File("demo.docx");if (file.exists()) {file.createNewFile();}OutputStream os = new FileOutputStream(file);int read = 0;byte[] bytes = new byte[1024 * 1024];//先读后写while ((read = inputStream.read(bytes)) > 0) {byte[] wBytes = new byte[read];System.arraycopy(bytes, 0, wBytes, 0, read);os.write(wBytes);}os.flush();os.close();inputStream.close();} catch (Exception e) {e.printStackTrace();}}
