List of usage examples for java.io DataInputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream("Main.class")); int start = in.readInt(); if (start != 0xcafebabe) { System.out.println("not valid"); }//from w w w .j av a 2s .co m in.close(); System.out.println(in.readUnsignedShort() + "/" + in.readUnsignedShort()); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/postedresults.jsp"); URLConnection conn = url.openConnection(); conn.setDoInput(true);// ww w.j a va 2 s . c om conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); String content = "CONTENT=HELLO JSP !&ONEMORECONTENT =HELLO POST !"; out.writeBytes(content); out.flush(); out.close(); DataInputStream in = new DataInputStream(conn.getInputStream()); String str; while (null != ((str = in.readUTF()))) { System.out.println(str); } in.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { byte[] b = new byte[1]; URL url = new URL("http://www.server.com/a.gif"); URLConnection urlConnection = url.openConnection(); urlConnection.connect();// w w w. j a v a 2 s . c om DataInputStream di = new DataInputStream(urlConnection.getInputStream()); FileOutputStream fo = new FileOutputStream("a.gif"); while (-1 != di.read(b, 0, 1)) fo.write(b, 0, 1); di.close(); fo.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://www.java.com/"); URLConnection urlConnection = url.openConnection(); DataInputStream dis = new DataInputStream(urlConnection.getInputStream()); String html = "", tmp = ""; while ((tmp = dis.readUTF()) != null) { html += " " + tmp; }//from ww w .j a v a 2 s .c o m dis.close(); html = html.replaceAll("\\s+", " "); Pattern p = Pattern.compile("<title>(.*?)</title>"); Matcher m = p.matcher(html); while (m.find() == true) { System.out.println(m.group(1)); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String query = "name=yourname&email=youremail@yourserver.com"; URLConnection uc = new URL("http:// your form ").openConnection(); uc.setDoOutput(true);// w w w. j a v a 2s . c om uc.setDoInput(true); uc.setAllowUserInteraction(false); DataOutputStream dos = new DataOutputStream(uc.getOutputStream()); // The POST line, the Accept line, and // the content-type headers are sent by the URLConnection. // We just need to send the data dos.writeBytes(query); dos.close(); // Read the response DataInputStream dis = new DataInputStream(uc.getInputStream()); String nextline; while ((nextline = dis.readLine()) != null) { System.out.println(nextline); } dis.close(); }
From source file:DataIODemo.java
public static void main(String args[]) throws IOException { FileOutputStream fout = new FileOutputStream("Test.dat"); DataOutputStream out = new DataOutputStream(fout); out.writeDouble(98.6);//from w ww.j a va 2 s. c o m out.writeInt(1000); out.writeBoolean(true); out.close(); FileInputStream fin = new FileInputStream("Test.dat"); DataInputStream in = new DataInputStream(fin); double d = in.readDouble(); int i = in.readInt(); boolean b = in.readBoolean(); System.out.println("Here are the values: " + d + " " + i + " " + b); in.close(); }
From source file:Main.java
public static void main(String[] atgs) throws Exception { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java.txt"))); out.writeUTF(""); out.writeBytes("a"); out.writeChars("aaa"); out.close();/*from w w w . j a v a 2s.c om*/ DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("java.txt"))); System.out.println(in.readUTF()); byte[] buf = new byte[1024]; int len = in.read(buf); System.out.println(new String(buf, 0, len)); in.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 }; DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat"))); fout.writeInt(data.length);/*from ww w .ja va2 s.c o m*/ for (double d : data) fout.writeDouble(d); DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat"))); int num = fin.readInt(); double avg = 0.0; double d; for (int i = 0; i < num; i++) { d = fin.readDouble(); avg += d; System.out.print(d + " "); } fin.close(); fout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL google = new URL("http://www.google.com/"); URLConnection googleConnection = google.openConnection(); DataInputStream dis = new DataInputStream(googleConnection.getInputStream()); StringBuffer inputLine = new StringBuffer(); String tmp;// w w w .j av a 2 s.co m while ((tmp = dis.readLine()) != null) { inputLine.append(tmp); System.out.println(tmp); } // use inputLine.toString(); here it would have whole source dis.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream fileIn = new FileInputStream("data.txt"); DataInputStream dataIn = new DataInputStream(fileIn); System.out.println(dataIn.readUTF()); int counter = dataIn.readInt(); double sum = 0.0; for (int i = 0; i < counter; i++) { double current = dataIn.readDouble(); System.out.println("Just read " + current); sum += current;//from w ww.j a va 2 s. c om } System.out.println("\nAverage = " + sum / counter); dataIn.close(); fileIn.close(); }