Discussion:
How to include/access non-java files in project.
jeff.parent
2009-06-04 15:51:41 UTC
Permalink
So I'm sure this isn't so much a netbeans issue as a general java issue but I can't find the resolution anywhre.



I have a non-java file (a DTD file for XML) that I want to include into my project. I then want to be able to access that file at runtime by either including it into the JAR file or having it live next to my class files when I install my project. The install path is user definable so I can not hardcode the location of the file. Does anyone know how I can access a file that is included in my project?
Cush1978
2009-06-04 17:06:19 UTC
Permalink
Sure. You add it to your class path like source code. Then:



InputStream inStream = getClass().getClassLoader().getResourceAsStream("path/to/your/file.dtd");
Melongo Annabel
2009-06-05 01:49:55 UTC
Permalink
Jeff,
For user to save files in your application, you should at least give them a directory on where to save it. The general pattern in dealing with such files is to create a naming convention like myfile20090604 where the last number are for example today's date. In doing so, you can retrieve each file that was, let's say, created today by "cutting" the "myfile" prefix and manipulating the 20090604 number into a date format by using String utilities. Hope this helps.




________________________________
From: jeff.parent <***@gmail.com>
To: ***@netbeans.org
Sent: Thursday, June 4, 2009 10:51:41 AM
Subject: [nbusers] How to include/access non-java files in project.

So I'm sure this isn't so much a netbeans issue as a general java issue but I can't find the resolution anywhre.



I have a non-java file (a DTD file for XML) that I want to include into my project. I then want to be able to access that file at runtime by either including it into the JAR file or having it live next to my class files when I install my project. The install path is user definable so I can not hardcode the location of the file. Does anyone know how I can access a file that is included in my project?
Continue reading on narkive:
Loading...