List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:TestEOF.java
public static void main(String[] args) throws IOException { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("TestEOF.java"))); while (in.available() != 0) System.out.print((char) in.readByte()); }
From source file:ReadBinaryFile.java
public static void main(String[] args) throws Exception { NumberFormat cf = NumberFormat.getCurrencyInstance(); File file = new File("product.dat"); DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); boolean eof = false; while (!eof) { Product movie = readMovie(in);//from w ww . j a v a2s. co m if (movie == null) eof = true; else { String msg = Integer.toString(movie.year); msg += ": " + movie.title; msg += " (" + cf.format(movie.price) + ")"; System.out.println(msg); } } 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();//w ww . j a va 2s . com 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:SquareServer.java
public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); ServerSocket ss = new ServerSocket(port); while (true) { Socket s = ss.accept();/* w w w .j a va 2 s . c o m*/ InputStream is = s.getInputStream(); DataInputStream dis = new DataInputStream(is); double value = dis.readDouble(); value *= value; OutputStream os = s.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeDouble(value); s.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt"))); out2.writeDouble(3.14159);//from w ww . java2 s .co m out2.writeUTF("Square root of 2"); out2.close(); DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt"))); System.out.println(in5.readDouble()); System.out.println(in5.readUTF()); }
From source file:Main.java
public static void main(String[] args) throws Exception { String host = "host"; int port = 25; String from = "from@from.net"; String toAddr = "to@to.net"; Socket servSocket = new Socket(host, port); DataOutputStream os = new DataOutputStream(servSocket.getOutputStream()); DataInputStream is = new DataInputStream(servSocket.getInputStream()); if (servSocket != null && os != null && is != null) { os.writeBytes("HELO\r\n"); os.writeBytes("MAIL From:" + from + " \r\n"); os.writeBytes("RCPT To:" + toAddr + "\r\n"); os.writeBytes("DATA\r\n"); os.writeBytes("X-Mailer: Java\r\n"); os.writeBytes(/* w w w.j a v a2 s . c om*/ "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n"); os.writeBytes("From:" + from + "\r\n"); os.writeBytes("To:" + toAddr + "\r\n"); } os.writeBytes("Subject:\r\n"); os.writeBytes("body\r\n"); os.writeBytes("\r\n.\r\n"); os.writeBytes("QUIT\r\n"); String responseline; while ((responseline = is.readUTF()) != null) { if (responseline.indexOf("Ok") != -1) break; } }
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);/* w w w .j a v a2 s .co 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[] args) throws IOException { String s = "Hello from java2s.com!!"; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); dos.writeChars(s);/* ww w . ja v a 2 s. c o m*/ dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { char c = dis.readChar(); System.out.print(c); } }
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 w w w . j a v a2 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:InputOutputDemoBinaryFile.java
public static void main(String[] a) throws Exception { //Write primitive values to a binary file "java2s.dat": DataOutputStream dos = new DataOutputStream(new FileOutputStream("java2s.dat")); dos.writeInt(228);/* w ww .j av a 2s . c o m*/ dos.writeChar(' '); dos.writeUTF("Java Source and Support at www.java2s.com"); dos.close(); //Read primitive values from binary file "java2s.dat": DataInputStream dis = new DataInputStream(new FileInputStream("java2s.dat")); System.out.println(dis.readInt() + "|" + dis.readChar() + "|" + dis.readUTF()); }