开发者

how do i create http visible files from java web application?

How can I create files visible by http protocol from java web application in web/myFiles folder ?

Is this even possible ?

for the following code :

String realPath = getServletContext().getRealPath("/");
    System.out.printl开发者_开发知识库n(realPath);

    try {
        BufferedWriter out = new BufferedWriter(new FileWriter( realPath + "\\myFiles\\test.txt"));
        out.write("aString\nthis is a\nttest");
        out.close();
    } catch (IOException e) {
        System.out.println("Exception " + e);

    }

i keep getting the error :

Exception java.io.FileNotFoundException: C:\Documents and Settings\Andrei\My Documents\NetBeansProjects\SemanticCashUpV1.0\build\web\myFiles\test.txt (The system cannot find the path specified)


Yes possible,

You need to create file in public web area.

near to WEB-INF Dir.

you can get path to public web space by

request.getServletContext().getRealPath("/");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜