Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) throws IOException {
- new Main().printBytesAndNames();
- }
- private void printBytesAndNames() throws IOException {
- byte[] data = new byte[1000];
- Map<Integer, String> sizeAndName = new HashMap<>();
- for(Path p : listFiles()) {
- new RandomAccessFile(p.toFile(), "r").readFully(data);
- int sum = 0;
- for(byte b : data) {
- sum += b;
- }
- sizeAndName.put(sum, p.getFileName().toString());
- }
- List<Integer> intList = new ArrayList<>(sizeAndName.keySet());
- Collections.sort(intList);
- for(int i : intList) {
- System.out.println(i + ", " + sizeAndName.get(i));
- }
- }
- List<Path> listFiles() throws IOException {
- return Files.list(Paths.get("./src/images"))
- .filter(Files::isRegularFile)
- .collect(Collectors.toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement