List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java
public static File createTempFile(String prefix, String ext, String content) throws IOException { File res = File.createTempFile(prefix, ext); try (FileWriter fw = new FileWriter(res)) { BufferedWriter bw = new BufferedWriter(fw); bw.append(content);/*w w w . ja va 2s .co m*/ bw.flush(); } return res; }
From source file:Main.java
public static boolean saveFile(String str, File path) { BufferedWriter bw = null; try {//www.ja v a 2 s . c o m bw = new BufferedWriter(new FileWriter(path)); bw.write(str); bw.flush(); return true; } catch (IOException e) { e.printStackTrace(); return false; } finally { if (bw != null) { try { bw.close(); } catch (IOException e) { // ignore } } } }
From source file:Main.java
public static void writeParam(HttpURLConnection urlConnection, String param) { try {/*from w w w .j a v a 2s . c o m*/ BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8")); writer.write(param); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void toStream(final String str, final OutputStream stream, final Charset charset) throws IOException { final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream, charset)); try {//from www . j a v a2 s . c o m writer.write(str); } finally { writer.flush(); writer.close(); } }
From source file:Main.java
public static boolean string2File(String res, File file) { if (file == null || res == null) return false; BufferedWriter bufferedWriter = null; try {/*from w ww.j a v a 2s . co m*/ bufferedWriter = new BufferedWriter(new FileWriter(file)); bufferedWriter.write(res); bufferedWriter.flush(); return true; } catch (IOException e) { e.printStackTrace(); if (file.exists()) file.delete(); return false; } finally { try { if (bufferedWriter != null) bufferedWriter.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static void writeUserInfo(String[] info, Context c) throws IOException { File f = c.getFileStreamPath(userInfoPath); if (!f.exists()) { f.createNewFile();/*www. j a v a2s. co m*/ } String output = ""; for (int n = 0; n < info.length; n++) { output += info[n] + eol + separator + eol; } BufferedWriter out = null; out = new BufferedWriter(new OutputStreamWriter(c.openFileOutput(userInfoPath, Context.MODE_PRIVATE))); out.write(output); out.flush(); out.close(); userInfo = info; }
From source file:Main.java
public static void writeFile(String path, String content, boolean append) throws FileNotFoundException { //File file = new File(path); FileOutputStream writerStream = new FileOutputStream(path, append); BufferedWriter writer = null; try {/*from w ww. ja v a 2 s . c om*/ writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8")); writer.write(content); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e1) { } } } }
From source file:jt56.comm.code.util.CommonPageParser.java
public static void WriterPage(VelocityContext context, String templateName, String fileDirPath, String targetFile) {//from w w w . jav a 2s. c o m try { File file = new File(fileDirPath + targetFile); if (!(file.exists())) { new File(file.getParent()).mkdirs(); } else if (isReplace) { log.info("?:" + file.getAbsolutePath()); } Template template = ve.getTemplate(templateName, "UTF-8"); FileOutputStream fos = new FileOutputStream(file); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); template.merge(context, writer); writer.flush(); writer.close(); fos.close(); log.info("?" + file.getAbsolutePath()); } catch (Exception e) { log.error(e); } }
From source file:manager.GameElement.java
public static void save() throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter("scores.json")); bw.write(toJSON().toJSONString());/* w ww . j a v a 2 s . c om*/ bw.flush(); }
From source file:edu.isi.webserver.FileUtil.java
public static void writeStringToFile(String string, String fileName) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); writer.write(string);//from w w w.ja v a2s. c om writer.flush(); writer.close(); }