Codice: Seleziona tutto
import java.io.* ;
public class PipedIOSample extends Thread {
protected DataInputStream iStream ;
120
Capitolo 4. Input/Output
public PipedIOSample(InputStream i) {
this.iStream = new DataInputStream(i);
}
public void run() {
try {
String str;
while (true) {
str = iStream.readUTF();
System.out.println("Letta: " + str);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) throws IOException {
PipedOutputStream o = new PipedOutputStream();
PipedInputStream iStream = new PipedInputStream(o);
DataOutputStream oStream = new DataOutputStream(o);
(new PipedIOSample(iStream)).start();
for (int i = 0; i < args.length; i++) {
System.out.println("Scrivo: " + args[i]);
oStream.writeUTF(args[i]);
}
oStream.close();
}
}
e uno postatomi da spidernetlab, grazie
Codice: Seleziona tutto
import java.io.*;
public class Read {
public static void main(String args[]) throws Exception {
byte[] b = {1, 2, 3, 4, 5};
PipedOutputStream poStream = new PipedOutputStream();
PipedInputStream piStream = new PipedInputStream();
//piped input stream connect to the piped output stream
piStream.connect(poStream);
//Writes specified byte array.
poStream.write(b, 0, 5);
//Reads the next byte of data from this piped input stream.
for (int i = 0; i < b.length; i++) {
System.out.println(piStream.read());
}
// Closes piped input stream
poStream.close();
// Closes piped output stream
piStream.close();
}
}se si può saltare perchè non farlo?
grazie per le risposte, non trovo l'utilità di queste classi se non strettamente necessarie

