List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { File temp = File.createTempFile("pattern", ".dat"); temp.deleteOnExit();/*w w w. ja v a 2 s . com*/ BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write("asdf"); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter("filename", true)); out.write("aString"); out.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); bw.append("java2s.com"); bw.close(); System.out.println(sw.getBuffer()); // appending after closing will throw error bw.append("2"); System.out.println(sw.getBuffer()); }
From source file:Main.java
public static void main(String[] args) throws Exception { String multilineString = "This is line 1\nthis is line 2\nthis is last line"; FileWriter fileWriter = new FileWriter("multiline.txt", true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(multilineString + "\n"); bufferedWriter.flush();//from w w w .jav a 2 s . c o m bufferedWriter.close(); fileWriter.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String strLine = in.readLine(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); out.write(strLine, 0, strLine.length()); out.flush();/*from w ww .j av a 2 s .c o m*/ in.close(); out.close(); }
From source file:MainClass.java
public static void main(String args[]) { try {//from w w w. j a va2 s . c o m FileWriter fw = new FileWriter(args[0]); BufferedWriter bw = new BufferedWriter(fw); for (int i = 0; i < 12; i++) { bw.write("Line " + i + "\n"); } bw.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];//from w w w . j a va2 s . c om URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoInput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];/* w w w . j ava 2 s.com*/ URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoOutput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileWriter file = new FileWriter("a.html"); BufferedWriter buffer = new BufferedWriter(file); PrintWriter out = new PrintWriter(buffer); out.println("<html>\n\t<body>"); out.println("\t</body>\n</html>"); out.close();/*from ww w . j av a 2 s . c om*/ buffer.close(); file.close(); }
From source file:BufferedWriterDemo.java
public static void main(String args[]) throws Exception { FileWriter fw = new FileWriter(args[0]); BufferedWriter bw = new BufferedWriter(fw); // Write strings to the file for (int i = 0; i < 12; i++) { bw.write("Line " + i + "\n"); }//from ww w .j a v a 2 s. c o m // Close buffered writer bw.close(); }