Write a txt file in web-inf folder of a web application in Spring MVC
<p>I want to create a .txt file on the server(of the domain on which the .war file will be deployed) and want it to download it via a download link. I can create and save the txt on my PC's desktop using user.home and getting the absolute path.</p>

<p>I have used ServletContext to get the context path. When I try to save file on that path, the error says, java.io.IOException: The system cannot find the path specified.</p>

<p>Now can someone tell me how to do it so that when I deploy the .war file I can write and download the file.</p>

<p>Controller:</p>

<pre><code>@Autowired
ServletContext context;
@RequestMapping(value = "/calculate")
public String getDataQuote(ModelMap map, HttpSession session, @ModelAttribute("dataBean") DataBean dataBean) {
    Calculator calc = new Calculator();
    Quote quote = calc.calculate(dataBean);
    Writer writer = new Writer();
    writer.printCloudData(quote, context);
    map.addAttribute(quote);
    return "result";
}
</code></pre>

<p>File Writer:</p>

<pre><code>public void printData(Bean bean, ServletContext context) {

    try {
        String path = context.getRealPath("/WebContent/files/");
        System.out.println(path);
        path = path.replace("\\", "/");
        File file = new File(path + "/files", "abc.txt");
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(bean.a);
        bw.newLine();
        bw.newLine();
        bw.write(bean.b);
        bw.close();
        } catch (
            IOException e)
        {
            e.printStackTrace();
        }
}
</code></pre>

<p>Everytime I run this controller, it gives this error:</p>

<pre><code>java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at com.business.Writer.printQuotationData(Writer.java:32)
at com.controler.DefaultController.getQuote(DefaultController.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
</code></pre>

<p>any help would be appreciated.
Thanks.</p>