0

Getting below Error with following Code: I'm passing thefile name with full add in FileInputStream constructor. Ex-: localhost:8080/projectName/OuterFolder/InnerFloder/example.doc

logger.info("File Path: "+ path+"/OuterFolder/InnerFloder/"+fileName);

POIFSFileSystem  fs = new POIFSFileSystem(new 
                 FileInputStream(path+"/OuterFolder/InnerFloder/"+fileName));
http:\localhost:8080\projectName\OuterFolder\InnerFloder\Example.doc (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at com.avi.service.UserService.createPolicy(UserService.java:1339)
    at com.avi.service.UserService$$FastClassByCGLIB$$de8fbe27.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:617)
    at com.avi.service.UserService$$EnhancerByCGLIB$$7c22f094_2.createPolicy(<generated>)
    at com.avi.controller.TestController.openPolicy(TestController.java:2733)
5
  • 1
    Shouldn't "Example.doc" be inside the double quotes(in the second line) ? Commented Aug 5, 2013 at 10:33
  • What is the log output? What is path? Commented Aug 5, 2013 at 10:33
  • 1
    path is a string variable having full path like:- localhost:8080/projectName Commented Aug 5, 2013 at 10:35
  • @Andreas: here is the logger output- File Path: localhost:8080/projectName/OuterFolder/InnerFloder/Example.doc Commented Aug 5, 2013 at 10:52
  • @Avi See shyams answer below Commented Aug 5, 2013 at 10:53

2 Answers 2

3
http:\localhost:8080\projectName\OuterFolder\InnerFloder\Example.doc

Is not a valid file path. On windows there is no "drive" letter "http:" like "C:". In fact I doubt, an "InnerFloder" exists too.

If you get it from a web application, use the following in:

URL url = new URL(path + "/OuterFolder/InnerFloder/Example.doc");
InputStream in = url.openStream();

To write the file somewhere (you cannot write it back to the web app http://...), select a file:

File file = new File("C:/OuterFolder/InnerFloder/" + fileName);
file.getParentFile().mkdirs(); // Create any missing directories
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
fs.writeFileSystem(out);
out.close();

This is a new file.

Sign up to request clarification or add additional context in comments.

5 Comments

Shouldn't it be url.openStream()?
its working @Joop but it's not working with FileWriter class
@AdrianJandl: you are right. It should be url.openStream() because a static reference to the non-static method openStream() from the type URL
Same exception with FileWriter writer= new FileWriter(path+"/downloads/policies/currentASC.doc") and URL can't be use with FileWriter class.
@AdrianJandl : corrected, thanks. @Avi: with http: there need not exist any file on the file system. I have extended the answer; FileWriter (all with ...Writer/Reader) is for text, .doc is binary data and hence one needs ...Stream.
1

FileInputStream needs an actual file path in the file system not a URL.

2 Comments

It is right?? localhost:8080/projectName/OuterFolder/InnerFloder/example.doc
No, localhost:8080/... is not a valid local path name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.