简体   繁体   中英

Servlet : create text file using servlets in eclipse

when i try to create a text file usnig servlet in eclipse it generate an exception FileNotFound

File file = new File("WebContent/WEB-INF/user.txt");
file.createNewFile();

after this the file not found exception throw.

you don't need to give the path.

File file = new File("user.txt");
file.createNewFile();

This will create a file user.txt under Web-Inf .

The Exception is because the path does not exists. Use PremGenError's answer for the default location, or If you want to create a new path do file.mkdirs()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM