Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class StreamExample {
- public static void main(String[] args) throws IOException {
- FileInputStream in = new FileInputStream("file.dat");
- ArrayList<Integer> arrayList = new ArrayList<Integer>();
- for (;;) {
- int x = in.read();
- if (x == -1) {
- break;
- }
- arrayList.add(x);
- }
- System.out.println(arrayList);
- byte[] bytes = new byte[arrayList.size()];
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = (byte) (int) arrayList.get(i);
- }
- System.out.println(Arrays.toString(bytes));
- in.close();
- FileOutputStream out = new FileOutputStream("file2.dat");
- out.write(bytes);
- out.close();
- }
- }
Add Comment
Please, Sign In to add comment