我正在開發一個程序,在管理員給定的特定時間將文件上傳到服務器,管理員輸入多個值(小時,分鐘)。計劃多次在Java中啓動一個方法
實施例:
[Hours,Minutes]= [2,12] [ 2,15],[ 5,20 ]
我保存在CSV文件中的那些值。
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("C:/Users/BACKENDPC1/Desktop/timer.csv"));
String line = null;
while ((line = reader.readLine()) != null) {
lines.add(line);
}} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
//Get the Date corresponding to 11:01:00 pm today.
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH");
Format formatter = new SimpleDateFormat("m");
Format sec=new SimpleDateFormat("s");
/*heur=getList().get(i).substring(0, getList().get(i).indexOf(substr));
minute=getList().get(i).substring(getList().get(i).indexOf(substr) + substr.length());
System.out.println("Time selected is: "+heur+","+minute);*/
while (i<lines.size()) {
heur=lines.get(i).substring(0, lines.get(i).indexOf(substr));
minute=lines.get(i).substring(lines.get(i).indexOf(substr) + substr.length());
System.out.println(sdf.format(calendar.getTime()));
System.out.println(Integer.parseInt(formatter.format(new Date())));
if(Integer.parseInt(sdf.format(calendar.getTime()))==Integer.parseInt(heur)&&(Integer.parseInt(formatter.format(new Date()))==Integer.parseInt(minute))){
System.out.println(Integer.parseInt(heur)+"H"+ Integer.parseInt(minute));
calendar.set(Calendar.HOUR_OF_DAY,Integer.parseInt(heur));
calendar.set(Calendar.MINUTE, Integer.parseInt(minute));
calendar.set(Calendar.SECOND, 0);
Date time = calendar.getTime();
timer = new Timer();
timer.schedule(new RemindTask(), time);
i++;
}}
i=1;
start();
/* timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);*/
}
class RemindTask extends TimerTask {
public void run() {
up.Uplaod();
long start = new Date().getTime();
long end=0;
int numIndexed=0;
boolean cond=true;
end = new Date().getTime();
cond=false;
// System.out.println("Indexing " + numIndexed + " files took "
// + (end - start) + " milliseconds");
timer.cancel();
//Terminate the timer thread
}
我運行此方法來安排執行上傳。它的工作原理兩次之後,我得到一個錯誤:在線程「AWT-EventQueue的 - 0」 java.lang.NumberFormatException
例外:對於輸入字符串:「小時」
在java.lang.NumberFormatException。 forInputString(未知來源)
在java.lang.Integer.parseInt(未知來源)
在java.lang.Integer.parseInt(未知來源)
在Reminder.start(Reminder.java:64)
在提醒.start(Reminder.java:80)
at csvFileUploadMulti $ 4.actionPerformed(csvFileUploadMulti.java:269)
在javax.swing.AbstractButton.fireActionPerformed(來源不明)
在javax.swing.AbstractButton中的$ Handler.actionPerformed(來源不明)
在javax.swing.DefaultButtonModel.fireActionPerformed(來源不明)
在javax.swing中.DefaultButtonModel.setPressed(未知來源)
在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(未知來源)
在java.awt.Component.processMouseEvent(未知來源)
在javax.swing.JComponent.processMouseEvent (Unknown Source)
at java.awt.Component.processEvent(Unknown Sou RCE)
在java.awt.Container.processEvent(未知來源)
在java.awt.Component.dispatchEventImpl(未知來源)
在java.awt.Container.dispatchEventImpl(未知來源)
在java.awt中.Component.dispatchEvent(未知來源)
在java.awt.LightweightDispatcher.retargetMouseEvent(未知來源)
在java.awt.LightweightDispatcher.processMouseEvent(未知來源)
在java.awt.LightweightDispatcher.dispatchEvent(未知來源)
at java.awt.Container.dispatchEventImpl(Unknown Source)
在java.awt.Window.dispatchEventImpl(未知來源)
在java.awt.Component.dispatchEvent(未知來源)
在java.awt.EventQueue.dispatchEventImpl(未知來源)
在java.awt.EventQueue中。訪問$ 400(來源不明)
在java.awt.EventQueue中的$ 3.run(來源不明)
在java.awt.EventQueue中的$ 3.run(來源不明)
在java.security.AccessController.doPrivileged(本機方法)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDo主要的$ 1doIntersectionPrivilege(來源不明)
在java.awt.EventQueue中的$ 4.run(來源不明)
在java.awt.EventQueue中的$ 4.run(來源不明)
在java.security.AccessController.doPrivileged(本機方法)
在java.security.ProtectionDomain $ 1.doIntersectionPrivilege(來源不明)
在java.awt.EventQueue.dispatchEvent(來源不明)
在java.awt.EventDispatchThread.pumpOneEventForFilters(來源不明)
在java.awt.EventDispatchThread .pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsFo rHierarchy(未知來源)
在java.awt.EventDispatchThread.pumpEvents(未知來源)
在java.awt.EventDispatchThread.pumpEvents(未知來源)
在java.awt.EventDispatchThread.run(未知來源)
有人可以幫我嗎?
NumberFormatException:對於輸入字符串:「小時」 – 2014-08-27 09:35:18
字符串「Hours」不會被解析爲「int」。改變你應該提取實際數字的邏輯。 – 2014-08-27 09:36:06
它看起來像你csv有列名頭。你可能應該跳過它。 – talex 2014-08-27 09:42:31