store a txt file in war

Can i include a file.txt in war package and read it from servlet classes post deployment? I thow, but the jboss generate the error: file not found. What is the correct path specification?
[201 byte] By [wcollazzo] at [2007-9-26 21:25:18]
# 1

I'm not familiar with JBoss, but typically this would accessable from the from the WebApp's root directory. Depending on the platform (OS & App Server) other directories may or may not be accessable.

I usually use this little helper class to drop a file in the WebApps root.

import java.io.IOException;

import java.io.FileWriter;

import java.util.Date;

import java.text.DateFormat;

/**

* A helper class that can be used to mark directories

*/

public class DirectoryUtils {

/**

* mark the default data directory with a

* marker derived from the calss name.

* Usage

*<CODE>

*DirectoryUtils.markDirectory( this ) ;

*DirectoryUtils.markDirectory( getClass().getName() ) ;

*</CODE>

* @param that object from which to derive class name

* @return <tt>true</tt> if sucessfull

* @deprecated this is redundant calls may be removed.

*/

public static boolean markDirectory( Object that ) {

return markDirectory( that.getClass().getName() ) ;

}

/**

* Marks the data directory with a marker.

* Usage

*<CODE>

*DirectoryUtils.markDirectory( this ) ;

*DirectoryUtils.markDirectory( getClass().getName() ) ;

*</CODE>

* @param dataFileName the class name to be used as a filename

* @return <CODE>true</CODE> if sucessfull

* @deprecated this is redundant calls may be removed.

*/

public static boolean markDirectory( String dataFileName ) {

boolean bRetVal = false ;

String _dataFileName = dataFileName + ".cwd" ;

String content = "# " + _dataFileName ;

String timeStamp = "# " + DateFormat.getDateTimeInstance().format( new Date() ) ;

try {

FileWriter fileWriter = new FileWriter( _dataFileName ) ;

fileWriter.write( content, 0, content.length() ) ;

fileWriter.write( timeStamp, 0, timeStamp.length() ) ;

fileWriter.flush() ;

fileWriter.close() ;

bRetVal = true;

}

catch ( IOException e) {

System.err.println( "markDirectory() : " + e.toString() ) ;

e.printStackTrace() ;

}

return bRetVal ;

}

}

MartinS. at 2007-7-3 21:13:45 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
I used JBoss war to store a XML file. It put the subdirectory of the root. The servlet class can read it. Can u make sure the file path coreect in your code?
ytan022 at 2007-7-3 21:13:46 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
I'm not sure why you are doing this , but you may want to use the inti methodof one of your servlets to use the classloader of that serverl to get the file.eg; InputStream in = myservlet.class.getResourceAsStream("filename"); Regards,TK.
TravisK at 2007-7-3 21:13:46 > top of Java-index,Other Topics,Patterns & OO Design...