| 9 | static Random rand = new Random(47); |
| 10 | static final int SIZE = 1000; |
| 11 | public static void |
| 12 | main(String[] args) throws Exception { |
| 13 | // Write bytes to a file: |
| 14 | byte[] bytes = new byte[SIZE]; |
| 15 | rand.nextBytes(bytes); |
| 16 | Files.write(Paths.get("bytes.dat"), bytes); |
| 17 | System.out.println("bytes.dat: " + |
| 18 | Files.size(Paths.get("bytes.dat"))); |
| 19 | |
| 20 | // Write an iterable to a file: |
| 21 | List<String> lines = Files.readAllLines( |
| 22 | Paths.get("../streams/Cheese.dat")); |
| 23 | Files.write(Paths.get("Cheese.txt"), lines); |
| 24 | System.out.println("Cheese.txt: " + |
| 25 | Files.size(Paths.get("Cheese.txt"))); |
| 26 | } |
| 27 | } |
| 28 | /* Output: |
| 29 | bytes.dat: 1000 |