package net.studyinghttp; import java.io.*; import java.net.*; public class StreamTester { public static void main(String args[]) { Writer out; String data = "ƒeƒXƒg"; try { out = outputToFileStream("test"); writeData(out, data); out = outputToNetworkStream("127.0.0.1", 30000); writeData(out, data); } catch (IOException e) { e.printStackTrace(); } } static void writeData (Writer out, String data) throws IOException { BufferedWriter bw = new BufferedWriter(out); bw.write(data); bw.close(); } static Writer outputToFileStream (String name) throws IOException { return new FileWriter(name); } static Writer outputToNetworkStream (String host, int port) throws IOException { Socket s = new Socket(host, port); return new OutputStreamWriter(s.getOutputStream()); } }