简体   繁体   English

Java更新后,Eclipse中的FileNotFoundException

[英]FileNotFoundException in Eclipse after Java updated

I have a program in which the client uploads a file and the file is stored in a database. 我有一个程序,客户端在其中上传文件,并且文件存储在数据库中。 Prior to Java updating on my computer, my project was working fine. 在计算机上更新Java之前,我的项目运行正常。 Now I am getting a FileNotFoundException . 现在,我得到了FileNotFoundException Eclipse is telling me: Eclipse告诉我:

The JAR file C:\\Program Files\\Java\\jre7\\lib\\rt.jar has no source attachment. JAR文件C:\\ Program Files \\ Java \\ jre7 \\ lib \\ rt.jar没有源附件。

Anybody come across this problem? 有人遇到这个问题吗?

My servlet code for uploading the file is standard: 我上传文件的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);
  }

There error is found in the putFileIntoDB method when the FileInputStream is created in the line fis=new FileInputStream(f): 在fis = new FileInputStream(f)行中创建FileInputStream时,在putFileIntoDB方法中发现错误:

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();
    }
}

Anybody else come across this problem? 还有其他人遇到这个问题吗?

Try below steps; 请尝试以下步骤;

Step 1 - Configure Eclilpse to use the JDK and not the JRE. 步骤1-配置Eclilpse以使用JDK而不是JRE。

Window->Preferences->Java->Installed JREs
Click "Add", "Standard VM", "Next"
For "JRE Home" click "Directory"
Locate your JDK directory...
Ex: C:\java\jdk1.6.0_24
Click "Finish"
Next check the JDK vs the JRE that is listed.
Click "Ok"

Step 2 - Configure your Project to use the JDK because it was created with the JRE as the "Installed JRE". 步骤2-将项目配置为使用JDK,因为它是使用JRE作为“ Installed JRE”创建的。 New project should be OK. 新项目应该可以。

Right click the project's name.
Choose "Properties", "Java Build Path"
Click the tab "Libraries".
Click "Add Libraries", select "JRE System Library", Next
Select the bottom item: Workspace default JRE (jdk1.x.x. etc....)
(Notice that it is now a JDK and not the JRE!)
Click "Finish"
Now remove the JRE libarary so you only have the JDK library.
ex: JRE System Library [JavaSE-1.6]
Click "OK"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM