You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2009/01/14 16:57:43 UTC

t5: accessing a text file under resources

Hi,

I put a robots.txt under resources, it is under classes after build, then
I'd like to access it from the code:

private final class RobotsTxtStreamResponse implements StreamResponse {

      public InputStream getStream() throws IOException {
          return new FileInputStream("robots.txt");
      }
  }

it does not work, any idea how to access that? thanks
-- 
View this message in context: http://www.nabble.com/t5%3A-accessing-a-text-file-under-resources-tp21458825p21458825.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: accessing a text file under resources

Posted by Angelo Chen <an...@yahoo.com.hk>.
Thanks, I found something similar:

 public InputStream getStream() throws IOException {
            String fn =
this.getClass().getResource("/robots.txt").getFile();
            return new FileInputStream(fn);
        }


Tapestry Infodea wrote:
> 
> Hi,
> try something like this:
> 
> private static final String WEB_BASED_PATH = "resources/robots.txt";
> 
> 

-- 
View this message in context: http://www.nabble.com/t5%3A-accessing-a-text-file-under-resources-tp21458825p21460394.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: t5: accessing a text file under resources

Posted by Tapestry Infodea <ta...@infodea.it>.
Hi,
try something like this:

private static final String WEB_BASED_PATH = "resources/robots.txt";

try {
			InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(WEB_BASED_PATH);
			DataInputStream din = new DataInputStream(is);
			BufferedReader br = new BufferedReader(new InputStreamReader(din));
			String line;
			while ((line = br.readLine()) != null) {
				//TODO ...
			}
			din.close();
		} catch (Exception e) {
			throw new TapestryException(e.getMessage(), resources.getLocation(), e);
		}


Angelo Chen ha scritto:
> Hi,
> 
> I put a robots.txt under resources, it is under classes after build, then
> I'd like to access it from the code:
> 
> private final class RobotsTxtStreamResponse implements StreamResponse {
> 
>       public InputStream getStream() throws IOException {
>           return new FileInputStream("robots.txt");
>       }
>   }
> 
> it does not work, any idea how to access that? thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org