I have a piece of code for reading CSV file from a zipInputStream. I am trying to read all entries of this zipInputStream, so if there is txt, pdf. I don't need any of them, the zip file supposed to be impressed by one and only one CSV file, if not, throw an error.
int CSVFile = 0;
Scanner scanner = null;
String line = "";
while((entry = zipinputstream.getNextEntry())!=null){
if(entry.getName.endsWith(".csv")){
CSVFile += 1;
scanner = new Scanner(zipinputstream);
}
}
if(CSVFile > 1 || CSVFile == 0){
throw new Exception("error");
}
if(scanner.hasNextLine()){
System.out.println(scanner.nextLine());
} else {
throw new Exception("there is no newline")
}
however I have tested this with a zip file impressed by a pdf and a CSV, CSV is not empty. it should print out a new line but it gives me "there is no newline". is there any logic issue I didn't see?