在Java中,可以通过使用InputStream和OutputStream类来创建数据流。以下是一些常见的方式:
InputStream inputStream = new FileInputStream("input.txt");
OutputStream outputStream = new FileOutputStream("output.txt");
byte[] data = {1, 2, 3, 4, 5};
InputStream inputStream = new ByteArrayInputStream(data);
OutputStream outputStream = new ByteArrayOutputStream();
PipedInputStream pipedInputStream = new PipedInputStream();
PipedOutputStream pipedOutputStream = new PipedOutputStream();
pipedInputStream.connect(pipedOutputStream);
InputStream inputStream = new DataInputStream(new FileInputStream("data.txt"));
OutputStream outputStream = new DataOutputStream(new FileOutputStream("output.txt"));
这些是一些常见的方式来创建数据流,您可以根据需要选择合适的流来处理输入和输出数据。