在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"));
這些是一些常見的方式來創建數據流,您可以根據需要選擇合適的流來處理輸入和輸出數據。