List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"), "8859_1")); out.write("asdf"); out.close();/*from w w w . j a v a 2s . co m*/ }
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"), "UTF8")); out.write("asdf"); out.close();//from ww w. java 2s . c om }
From source file:Main.java
public static void main(String args[]) throws Exception { String[] words = { "", "e", "a", "c" }; Writer w = new BufferedWriter(new OutputStreamWriter(System.out, "Cp850")); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); }//from w w w . jav a 2s .c om Arrays.sort(words); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); } w.flush(); w.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String[] words = { "", "e", "a", "c" }; Writer w = new BufferedWriter(new OutputStreamWriter(System.out, "Cp850")); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); }/*from w w w.j a v a2 s . c om*/ sortArray(Collator.getInstance(), words); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); } w.flush(); w.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {/*from ww w.j a v a 2 s. co m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {/*from w w w.j ava 2 s .c o m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// ww w . j a va2s .com char[] chars = new char[2]; chars[0] = '\u4F60'; chars[1] = '\u597D'; String encoding = "GB18030"; File textFile = new File("C:\\temp\\myFile.txt"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(textFile), encoding); writer.write(chars); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//from w ww .j ava2s . c o m OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, java.nio.charset.StandardCharsets.UTF_8); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "localhost"; Socket connection = null;//ww w. j av a2s. com connection = new Socket(hostname, DEFAULT_PORT); Writer out = new OutputStreamWriter(connection.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = connection.getInputStream(); BufferedInputStream buffer = new BufferedInputStream(raw); InputStreamReader in = new InputStreamReader(buffer, "8859_1"); int c; while ((c = in.read()) != -1) { if ((c >= 32 && c < 127) || c == '\t' || c == '\r' || c == '\n') { System.out.write(c); } } connection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); Socket socket = new Socket("127.0.0.1", 8080); String path = "/servlet"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")); wr.write("POST " + path + " HTTP/1.0\r\n"); wr.write("Content-Length: " + data.length() + "\r\n"); wr.write("Content-Type: application/x-www-form-urlencoded\r\n"); wr.write("\r\n"); wr.write(data);// w ww . j av a 2 s . c o m wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); String line; while ((line = rd.readLine()) != null) { System.out.println(line); } wr.close(); rd.close(); }