Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:01:42+00:00 2026-06-10T06:01:42+00:00

I have Netbeans 7.1.2 running and I am trying to access some text files

  • 0

I have Netbeans 7.1.2 running and I am trying to access some text files within a servlet:

package com.optimizations.cutting;

@WebServlet(name = "Servlet", urlPatterns = {"/Servlet"})
public class Servlet extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    System.out.println("in servlet "+System.currentTimeMillis());

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {

        DataManager dm = new DataManager();
        SheetInfo si = dm.loadSheetInfoCSV("sheetInfo.csv");
        ArrayList<Piece> pieces = dm.loadPiecesCSV("res/pieces4.csv");
....

I have placed the sheetInfo.csv and the pieces4.csv files everywhere i could think of, trying to acces them with a backslash ahead ( /sheetInfo.csv or /res/pieces4.csv )

when i say “everywhere i could think of” i mean : current directory (source packages), next to Servlet.java and all the other files I created (including DataManager.java which uses it). I also did the "Add folder" in the Properties window->Sources->Package Folder. (added 2 folders, just to make sure ). So my dear files are in 3 places all at once:

  • src/java/com/optimizations/cutting next to Servlet.java and DataManager.java

  • src/java/res

  • src/resources
    but i stll get the

    SEVERE: java.io.FileNotFoundException: resources/pieces4.csv (No such file or directory)
    
    at java.io.FileInputStream.open(Native Method)
    
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    
    at java.io.FileInputStream.<init>(FileInputStream.java:97)
    
    at java.io.FileReader.<init>(FileReader.java:58)
    
    at com.optimizations.cutting.DataManager.loadPiecesCSV(DataManager.java:98)`
    

I have also restarted the server (Glassfish 3.1.2)

(maybe this seems silly but I also need to know where and how should i place my files so they can be accessed from both the client and the server – my servlet will create some images(.jpg) and store them (where?) and will send the filenames back to a .jsp which will then show them in a colorbox)

thanks in advance.

edit

added some more lines of the error and
the call in DataManager.java:

public SheetInfo loadSheetInfoCSV(String filename){
    ....
    br = new BufferedReader( new FileReader(filename));
    String strLine = "";            

    //read comma separated file first line
    if ((strLine = br.readLine()) != null)
    ....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:01:44+00:00Added an answer on June 10, 2026 at 6:01 am

    The exception suggests that you were using FileInputStream to get an InputStream of it. This is not the right way when the resource concerns a classpath resource (all places where you attempted to put it in are part of the classpath). You should get a classpath resource as a classpath resource using ClassLoader#getResourceAsStream(), not as a local disk file system resource using FileInputStream.

    If the resource file foo.ext is placed in the same package as the class where you’re trying to load the resource (i.e. the DataManager class), then you can just use get an InputStream of it by its sole filename as follows:

    InputStream input = getClass().getResourceAsStream("foo.ext");
    

    Or when you’re inside the static context:

    InputStream input = DataManager.class.getResourceAsStream("foo.ext");
    

    If the resource foo.ext is placed in a different package than the class where you’re trying to load the resource, e.g. the com.example package, then you can get an InputStream of it by its classpath-relative path as follows, where the leading slash / takes you to the root of the classpath:

    InputStream input = getClass().getResourceAsStream("/com/example/foo.ext");
    

    Also here, the getClass() can be substituted by an arbitraty Foo.class, as long as the class is loaded by the same ClassLoader which has access to the same package structure.

    An alternative is to use the context ClassLoader as obtained from the current thread. It has access to everything. You only can’t specify a classpath-relative path, it is always relative to the root of the classpath (so no leading slash / should be used):

    InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/example/foo.ext");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a servlet built and running in Netbeans to run on
I am running Netbeans 7.0.1 under OS X and have created a number of
I have made two thread running together with Netbeans and i want to add
I am running Mac OS X 10.5.8 and am trying to run Netbeans 7.1.2.
I have a next problem. When I'm running project from NetBeans IDE evrything is
I'm trying to get up and running with git. I have set up a
I'm using netbeans, project: 'maven OSGI bundle', i have bundle activator running fine in
I have created some custom JPanel classes using the NetBeans GUI Builder. Next, I
I have a NetBeans project that I'm trying to compile manually from command-line ant
I am trying to get the sources for Netbeans IDE by running: hg clone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.