public static BufferedReader fileReaderAsResource(String filePath) throws IOException {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
if (is == null) {
throw new FileNotFoundException(" Not found: " + filePath);
}
return new BufferedReader(new InputStreamReader(is, DEFAULT_ENCODING));
}
This works for non-zip file. But for zip file, how to return a BufferedReader? The following doesn't work since 'fileName' is a relative path under my 'resources' directory:
public static BufferedReader fileZipReader(String fileName) throws IOException {
ZipFile zip = new ZipFile(fileName);
for(Enumeration e = zip.entries(); e.hasMoreElements();){
ZipEntry zipEntry = (ZipEntry) e.nextElement();
if(!zipEntry.isDirectory()){
return new BufferedReader(new InputStreamReader(zip.getInputStream(zipEntry)));
}
}
throw new FileNotFoundException("File not found: " + fileName);
}
How to change the 'fileZipReader' to make it work?