0

I need to write a file - abc.xlsx to folder - error and its path is : C:\Oracle\Middleware\Oracle_Home\user_projects\domains\test2\servers\error. Now from java code how to I get access to it? Currently have included the hard coded path: C:\work\abc.xlsx. I want to get path to the server folder of weblogic in a dynamic way since when my code will be deployed it has to work there also.

FileOutputStream out;
            try {
                out = new FileOutputStream(new File("C:\\work\\abc.xlsx"));

                workbook.write(out);  
                out.close(); 
                System.out.println("abc.xlsx written successfully on disk.");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
Roman C
  • 49,761
  • 33
  • 66
  • 176
coder
  • 149
  • 3
  • 4
  • 17
  • 1
    You're not supposed to. Take a step back and elaborate the concrete functional requirement for which you thought that this would be the right solution, then you can get the right solution. What exactly is the purpose of that file? Uploaded file? Temporary file? If uploaded file, then this is a duplicate: http://stackoverflow.com/q/18664579. If temporary file, then this is a duplicate: http://stackoverflow.com/q/31255366. – BalusC Jul 20 '15 at 07:19
  • this file which is written will be downloaded by the user from the jsp. – coder Jul 20 '15 at 07:25
  • Oh? Why are you writing it to server's disk file system instead of directly to HTTP response? In other words: why is the `out` pointing to `new FileOutputStream` instead of `response.getOutputStream()`? – BalusC Jul 20 '15 at 07:26
  • the requirement is that user fills in an excel file and uploads it. The backend code will process the uploaded file and generate error file which the user will download. Now there are 2 folders inside of the server folder of weblogic. one to store the uploaded file and another to store the error file. what is the better approach? – coder Jul 20 '15 at 07:33
  • The first is then your answer. – BalusC Jul 20 '15 at 07:34

0 Answers0