The following example shows how to read a file from zip file.
It iterates through all zip file entries until the exact file name
match is found. It also shows how to convert stream to string.
public static String streamToString(InputStream inputStream) {
StringBuilder sb = new StringBuilder();
BufferedReader br;
try {
br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
}
It gives the following output,
No match found : prop_xml_file.xml
No match found : test.txt
No match found : software.tsv
No match found : abc.txt
No match found : TWO/FOUR/
No match found : TWO/FOUR/FIVE/
Found matching file : TWO/FOUR/FIVE/abc.txt
----------------------------------------
Hello World
Hello World2