我有一個程序,客戶端上傳文件並將文件存儲在數據庫中。在我的電腦上更新Java之前,我的項目工作正常。現在我得到FileNotFoundException
。 Eclipse告訴我:在Java更新後的Eclipse中的FileNotFoundException
JAR文件C:\ Program Files \ Java \ jre7 \ lib \ rt.jar沒有源 附件。
有人遇到過這個問題嗎?
我的用於上載文件servlet代碼是標準:
if (!ServletFileUpload.isMultipartContent(request))
{return;}
try
{
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
courseID = items.get(0).getString();
homeworkID = items.get(1).getString();
File storeFile = new File(items.get(2).getName());
String fileName = storeFile.getName();
String mimeType = new MimetypesFileTypeMap().getContentType(storeFile); //for putting file into database
putFileIntoDB(uName, courseID, homeworkID, fileName, mimeType, storeFile);
}//try
catch (Exception ex)
{
request.setAttribute("msg", "There was an error: " + ex.getMessage());
request.getRequestDispatcher("/upload.jsp").forward(request, response);
}
有誤差在putFileIntoDB方法發現在該行中創建的FileInputStream當f是=新的FileInputStream(F):
void putFileIntoDB(String username, String courseID, String homeworkID, String fileName, String mime, File f) throws SQLException, IOException
{
FileInputStream fis = null;
java.sql.PreparedStatement pstmt = null;
java.sql.Connection conn = null;
try {
conn = ConnectionManager.getConnection();
conn.setAutoCommit(true);
fis = new FileInputStream(f);
pstmt = conn.prepareStatement("insert into files(username, courseID, assignmentID, fileName, mimeType, contents) values (?, ?, ?, ?, ?, ?)");
pstmt.setString(1, username);
pstmt.setString(2, courseID);
pstmt.setString(3, homeworkID);
pstmt.setString(4, fileName);
pstmt.setString(5, mime);
pstmt.setAsciiStream(6, fis, (int) f.length());
pstmt.executeUpdate();
conn.commit();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
finally
{
pstmt.close();
fis.close();
conn.close();
}
}
還有人遇到過這個問題嗎?
你檢查過,如果那個罐子在那個位置可用? – Parth 2013-03-17 18:38:06
是的,當我導航到那個位置時,rt.jar文件就在那裏。這就是爲什麼我不明白爲什麼它告訴我它沒有源附件。 – Lani1234 2013-03-17 18:45:30