List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:Main.java
public static void writeFile(File file, String data) throws IOException { FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); out.write(data);/*from w w w . jav a2 s . c o m*/ out.close(); }
From source file:Main.java
static void writeUtf(String text, String file) { Writer out;/* w w w .j a va 2s. c o m*/ try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); out.write(text); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void writeTextFile(File file, String text) { try {//from w ww .j av a 2s .c o m BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(text); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
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. ja v a2 s . c om 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 Process execute(String command) throws Exception { final Process process = new ProcessBuilder("sh").redirectErrorStream(true).start(); BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(process.getOutputStream())); stdOutput.write(command + "; exit\n"); stdOutput.flush();//from ww w . j a v a2 s . c o m stdOutput.close(); return process; }
From source file:Main.java
public static void writeParam(HttpURLConnection urlConnection, String param) { try {//ww w .j a v a2s. 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 BufferedWriter getWriter(File file, final String group, String comment) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(file)) { @Override/*from w w w . j a v a 2 s . c om*/ public void close() throws IOException { write("</" + group + ">"); super.close(); } }; bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); bw.newLine(); bw.newLine(); bw.write("<!--" + comment + "-->"); bw.newLine(); bw.newLine(); bw.write("<" + group + ">"); bw.newLine(); return bw; }
From source file:Main.java
public static void appendOneline(String fileName, String oneline) { PrintWriter out = null;/*from w w w . j a va2s .c o m*/ try { out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true))); out.print(oneline + "\n"); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { out.close(); } } }
From source file:Main.java
public static boolean saveStringToFile(String fileName, String saveString) { boolean saved = false; BufferedWriter bw = null;/*from w w w . j a va 2s . c o m*/ try { bw = new BufferedWriter(new FileWriter(fileName)); try { bw.write(saveString); saved = true; } finally { bw.close(); } } catch (IOException ex) { ex.printStackTrace(); } return saved; }
From source file:Main.java
public static void writeXml(String content, String path) { try {/*from w w w . java2 s. c o m*/ File file = new File(path); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8")); out.write(content); out.flush(); } catch (Exception e) { e.printStackTrace(); } }