Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.8 kB
3
Indexable
Never

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
/**
 *
 * @author amedeonapolitano
 */
public class NewMain {

    /**
     * @param args the command line arguments
     * @throws java.io.FileNotFoundException
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        ArrayList<String> listOfLines;
        try ( // TODO code application logic here
                BufferedReader bufReader = new BufferedReader(new FileReader("/Users/amedeonapolitano/Documents/prova.txt"))) {
            listOfLines = new ArrayList<>();
            String line = bufReader.readLine();
            while (line != null) {
                listOfLines.add(line);
                line = bufReader.readLine();
            }
        }
        boolean trovato = true;
        File f = new File("/Users/amedeonapolitano/Desktop/FILEPROVA");
        String[] files = f.list();
        for (String curr_nf : listOfLines) {
            trovato = false;
            for (String inp_fl : files) {
                if (curr_nf == inp_fl) {
                    trovato = false;
                } else {
                    trovato = true;
                }

            }
            if (trovato = true) {
                //System.out.println("file da eliminare" + curr_nf);
                File currentFile = new File(f.getPath(), curr_nf);
                currentFile.delete();
            }

        }

    }

}