tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Tapestry Wiki] Update of "Tapestry5HowToReadAFileFromContext" by BorutBolcina
Date Mon, 16 Feb 2009 23:25:10 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.

The following page has been changed by BorutBolcina:

New page:
One of your services needs a content of a file located at your web application's context folder.
More specifically, the file we want to read is in the config folder under the context directory.

public static TownNames buildTownNames(Context context, final Logger log) {
    return new TownNamesImpl(context, log);

TownNames.java is a very simple interface:
public interface TownNames {
    List<String> getAll();

And the implementation (TownNamesImpl.java) which demonstrates reading a file named towns.txt
from the config folder under the web app context folder:
public class TownNamesImpl implements TownNames {

    private List<String> townNames = new ArrayList<String>();

    public TownNamesImpl(Context context, Logger log) {
        String town = null;
        Resource configFile = new ContextResource(context, "config/towns.txt");
        try {
            InputStream is = configFile.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf8"));

            while ((town = br.readLine()) != null) {

        } catch (IOException e) {


    public List<String> getAll() {
        return Collections.unmodifiableList(townNames);


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

View raw message