import java. io. BufferedReader ;
import java. io. File ;
import java. io. FileReader ;
import java. io. IOException ;
import java. util. HashSet ;
import java. util. Set ; public class FolderFileNames { public static void main ( String [ ] args) { String folderPath = "homework" ; Set < String > setHomeWork = new HashSet < > ( ) ; File folder = new File ( folderPath) ; if ( folder. exists ( ) && folder. isDirectory ( ) ) { String [ ] fileNames = folder. list ( ) ; for ( String fileName : fileNames) { System . out. println ( fileName) ; setHomeWork. add ( fileName. split ( "\\." ) [ 0 ] ) ; } } else { System . out. println ( "文件夹不存在或不是一个文件夹。" ) ; } Set < String > allStuNames = new HashSet < > ( ) ; try { FileReader fileReader = new FileReader ( "file.txt" ) ; BufferedReader bufferedReader = new BufferedReader ( fileReader) ; String line; while ( ( line = bufferedReader. readLine ( ) ) != null ) { System . out. println ( line) ; allStuNames. add ( line) ; } bufferedReader. close ( ) ; } catch ( IOException e) { e. printStackTrace ( ) ; } allStuNames. removeAll ( setHomeWork) ; System . out. println ( allStuNames) ; }
}