Here you can find the source of writeToFile(String content, String fileName)
Parameter | Description |
---|---|
content | a parameter |
fileName | a parameter |
public static synchronized File writeToFile(String content, String fileName)
//package com.java2s; //License from project: LGPL import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; public class Main { /**/*from w ww. java 2 s . c om*/ * Creates file under temporary file directory and writes configuration to * it. Returns the created file. * * @param content * @param fileName * @return created file */ public static synchronized File writeToFile(String content, String fileName) { File temp = null; BufferedWriter bw = null; try { temp = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(temp), StandardCharsets.UTF_8)); bw.write(content); bw.flush(); } catch (RuntimeException e) { throw e; } catch (Exception e1) { e1.printStackTrace(); } finally { if (bw != null) { try { bw.close(); } catch (IOException e) { e.printStackTrace(); } } } return temp; } }