loading a resource

There is one tiny thing i would like to do. Just load a resource with my applicationsettings.
In GWT I would just use a Constant-Interface, in Vaadin I do get confused.
So i have a file ‘myconfigs.properties’ somewhere in my packaged app.
How do I get the content?

Hi.

Get the file like this:



URL url = MyClass.class.getResource( "/myconfigs.properties" );
if(url == null) {
  throw new FileNotFoundException();
}
File myFile = new File( url.toUri() );

I’d catch the URISyntaxException thrown by toUri() and re-throw it as a runtime exception with message “programming error”.

Next, send the resource to the user (just copying-pasing my code):


  public void sendFile( final File file, String filename ) {
    logger.info( "Sending file " + file.getAbsolutePath() );
    StreamSource streamSource = new StreamSource() {

      @Override
      public InputStream getStream() {
        try {
          return new FileInputStream( file );
        } catch ( FileNotFoundException e ) {
          e.printStackTrace();
          logger.error( "Could not send file " + file.getAbsolutePath(), e );
          return null;
        }
      }
    };
    getMainWindow().open( new StreamResource( streamSource, filename, this ) );
  }

Hope this helps.
Note: I guess this won’t work if the file is inside a JAR file. But in a webapp, it usually isn’t.