List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:Main.java
public static void writeParam(HttpURLConnection urlConnection, String param) { try {//w ww.j av a 2 s. c om 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 writeFile(String filename, String content) { File file = new File(filename); if (!file.exists()) { createFile(file);/* w w w . ja v a 2 s. c om*/ } BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(filename)); writer.write(content); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); writer = null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:Main.java
public static void writeTextFile(String[] text, String filename) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); for (int i = 0; i < text.length; i++) { writer.write(text[i]);/* ww w . j a v a 2 s.c o m*/ writer.newLine(); } writer.close(); }
From source file:Main.java
/** * Write data column.//from ww w. j a v a 2 s. c o m * * @param data the data * @param outputPath the output path */ public static void writeDataColumn(List<? extends Number> data, String outputPath) { File file = new File(outputPath); try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); System.exit(0); } try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for (Number value : data) { writer.write(value.toString() + "\n"); } writer.close(); } catch (IOException e) { e.printStackTrace(); System.exit(0); } }
From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java
private static void testWrite() { StopWatch stopWatch = new StopWatch(); stopWatch.start();//w ww . ja va 2 s . c o m try { File file = new File("test.txt"); file.deleteOnExit(); FileWriter fw = new FileWriter(file); BufferedWriter w = new BufferedWriter(fw); for (int i = 0; i < 50 * 1024 * 1024; i++) { w.append('x'); } w.close(); } catch (IOException e) { e.printStackTrace(); } stopWatch.stop(); System.out.printf("Writing file took %s\n", DurationFormatUtils.formatDurationHMS(stopWatch.getTime())); }
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 ww w. ja v a 2 s .com*/ writer.write(str); } finally { writer.flush(); writer.close(); } }
From source file:edu.washington.iam.tools.XMLHelper.java
public static String serializeXmlToString(XMLSerializable obj) throws IOException { StringWriter sw = new StringWriter(); BufferedWriter xout = new BufferedWriter(sw); obj.writeXml(xout);//from w w w . j av a 2 s. c o m xout.close(); return sw.toString(); }
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();/*from w w w . ja v a 2 s . c o 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 .j a v a 2s.c o m 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:FileHandler.java
private static void writeToFile(String txt, FileContents fc) throws IOException { int sizeNeeded = txt.length() * 2; if (sizeNeeded > fc.getMaxLength()) { fc.setMaxLength(sizeNeeded);/*w ww. ja va 2 s .co m*/ } BufferedWriter os = new BufferedWriter(new OutputStreamWriter(fc.getOutputStream(true))); os.write(txt); os.close(); }