Java by API/java.io/DataOutputStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
- 1 DataOutputStream: writeBoolean(boolean b)
- 2 DataOutputStream: writeByte(byte b)
- 3 DataOutputStream: writeChar(char ch)
- 4 DataOutputStream: writeDouble(double d)
- 5 DataOutputStream: writeFloat(float f)
- 6 DataOutputStream: writeInt(int i)
- 7 DataOutputStream: writeLong(long l)
- 8 DataOutputStream: writeShort(int i)
- 9 DataOutputStream: writeUTF(String str)
- 10 new DataOutputStream(FileOutputStream fileOutputStream)
DataOutputStream: writeBoolean(boolean b)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeByte(byte b)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeChar(char ch)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeDouble(double d)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeFloat(float f)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeInt(int i)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeLong(long l)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeShort(int i)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
DataOutputStream: writeUTF(String str)
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class MainClass extends Thread {
public MainClass() throws IOException {
}
public void run() {
try {
Socket socket = new Socket("127.0.0.1", 2000);
DataInputStream in = new DataInputStream(socket.getInputStream());
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
while (true) {
System.out.print("Enter response: ");
String response = console.readLine();
out.writeUTF(response);
String message = in.readUTF();
System.out.println(message);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
Thread t = new MainClass();
t.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
new DataOutputStream(FileOutputStream fileOutputStream)
/*
* Output:
*/
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class MainClass {
public static void main(String args[]) {
try {
FileOutputStream fos = new FileOutputStream(args[0]);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(false);
dos.writeByte(Byte.MAX_VALUE);
dos.writeChar("A");
dos.writeDouble(Double.MAX_VALUE);
dos.writeFloat(Float.MAX_VALUE);
dos.writeInt(Integer.MAX_VALUE);
dos.writeLong(Long.MAX_VALUE);
dos.writeShort(Short.MAX_VALUE);
fos.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}