java获取resources目录下的文件
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
@Service
public class BlacklistService {
public List<String> getBlacklist() throws IOException {
Resource resource = new ClassPathResource("blacklist.txt");
List<String> blacklist = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
blacklist.add(line);
}
}
return blacklist;
}
}