我正在處理一個程序,它告訴文件的上次修改日期是否在日期範圍From和date To中,如果它在範圍內,它將複製但是會出錯轉換上次修改日期時出錯
File src = new File(sourcefile + File.separator + strErrorFile[i]);
if(sourcefile.isDirectory())
{
ArrayList<Integer> alDateList = date(strList1);
int intDateFrom1 = alDateList.get(0);
int intDateTo1 = alDateList.get(1);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("After Format : " + sdf.format(src.lastModified()));
try
{
lastDate = Integer.parseInt(sdf.format(src.lastModified())); //line 362
} catch (NumberFormatException e) {
e.printStackTrace();
}
if(intDateFrom1 <= lastDate && intDateTo1 >= lastDate)
{
//copy
}
}
錯誤
java.lang.NumberFormatException: For input string: "09/10/2015"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.eclipse.wb.swt.FortryApplication$4.widgetSelected(FortryApplication.java:362)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.wb.swt.FortryApplication.open(FortryApplication.java:56)
at org.eclipse.wb.swt.FortryApplication.main(FortryApplication.java:610)
這不是一個有效的整數 - >「09/10/2015」,您可以做什麼來分割字符串用分隔符「/」,然後連接數組中的每個元素以使數字「091015」。請注意,如果將其轉換爲整數,則前導零將被刪除。 –
@OusmaneMahyDiaw我該如何改變它?對不起,新的 –
看到我的答案進一步的細節。 –