我想重新打开一个文件。我在输入流中有一个文件。我尝试过使用 Scanner 和 BufferedReader。但是在使用 close() 方法关闭文件后,我无法再次打开文件。请帮助如何再次打开文件。我写了下面的代码:
InputStream filename = getAttachstream();
int rows =0 ;
BufferedReader br= new BufferedReader(new InputStreamReader(filename));
String strLine = "";
try {
while( (strLine = br.readLine()) != null) {
rows++;
}
//br.reset();
br.close();
//br.reset();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(rows>0){
InputStream filename1 = getAttachstream();
Scanner inputStream1 = new Scanner(filename1);
for (int rowIncr = 1; inputStream1.hasNext(); rowIncr++) {
String data;
try {
data = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String [] values = data.split(",");
String curRowPartNumber = values[0];
String curRowQuantity = values[1];
if(rowIncr == 1)
{
if((values[0]==null || values[0].trim().length()<=0)
|| (values[1]==null || values[1].trim().length()<=0)
|| (values[2] != "") || !"Part Number".equalsIgnoreCase(values[0].trim())
|| !"Quantity".equalsIgnoreCase(values[1].trim())){
System.out.println("Invalid Excel sheet data");
throw new ECApplicationException(ECMessage._ERR_CMD_INVALID_DATAFORMAT, CLASSNAME,methodName);
}
}