0

I'm developing a JSF web application, with the current 2.1.7 JSF version.

Actually, I have a login page, associated with a session bean, which calls to a logic class "PersonCatalog", which is responsible for reading a text file .txt with the information of the persons, like a database but with files.

The problem is to access the file,
ever I get a NullException because the program doesn't finds the file. I'm not sure about the path I choose, here is the directory herarchy:

Application

 |-- build
 |-- src
       |--eci
           |--pdsw2012
               |--shoeople
                   |--beans
                       |--loginBean and others ...
                   |--logic
                       |--PersonCatalog and others...
                   |--persistence
                       |--files
                           |--persons.txt
 |-- WebContent
       |--WEB-INF
       |--META-INF
       |--a lot of xhtml pages ...

I'm using in PersonCatalog for read the person.txt file the follow code:

File readFile = new File(new String("src/eci/pdsw2012/shoeople/persistence/files/persons.txt"));

But I get:

java.lang.NullPointerException
at eci.pdsw2012.shoeople.logic.PersonCatalog.loadFile(PersonCatalog.java:31)

I have used the ExternalContext().getRealPath(), but it only shows inside Web-content folder.

I'm using Eclipse, and the default route is the installation folder of Eclipse, the is so strange:

String ruta = System.getProperty("user.dir");
System.out.println("DirAbs: " + ruta.getAbsolutePath());

and prints

 C:/Eclipse/
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Creativelair
  • 9
  • 1
  • 6

1 Answers1

0

The root of a deployed web application in this case would be the WebContent folder, which contains WEB-INF.

In the deployed version the src files are compiled into class files and placed in the following folder classes.

The path to persons.txt will be \WEB-INF\classes\eci\pdsw2012\shoeople\persistence\files\persons.txt

maple_shaft
  • 10,328
  • 4
  • 42
  • 70
  • Hey thank you maple, i move it and then it works!! thanks a lot friend – Creativelair Mar 19 '12 at 22:47
  • I have a problem, i dont know how to access that file from a .java file, i am using : ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/") + "files/personas.txt" But it doesnt works, save in another folder, thank you! – Creativelair Mar 20 '12 at 22:46
  • @Creativelair This seems like it may be a different problem. You should post this as different question. – maple_shaft Mar 21 '12 at 11:24