1 2 Previous Next 21 Replies Latest reply: Mar 2, 2013 7:55 AM by alley Go to original post RSS
      • 15. Re: FileNotFoundException error
        EJP
        I think the problem is created by the code stripper.getTextForRegion("class1")
        That's what I told you two days ago. Obviously it is returning an illegal character which gets lost during the conversion you mention.
        • 16. Re: FileNotFoundException error
          alley
          Hi rp0428,

          I had tested the println from my end, but the outputs were good. These are the println for path and filename after amending as per the suggestion from EPJ:

          run:
          C:/Users/MyName/Desktop/
          test
          .pdf
          Exception in thread "main" java.io.FileNotFoundException: C:\Users\MyName\Desktop\test
          .pdf (The filename, directory name, or volume label syntax is incorrect)
               at java.io.FileOutputStream.open(Native Method)
               at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
               at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
               at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1138)
               at org.apache.pdfbox.examples.util.ExtractTextByArea.main(ExtractTextByArea.java:106)
          Java Result: 1
          BUILD SUCCESSFUL (total time: 2 seconds)
          • 17. Re: FileNotFoundException error
            alley
            Yes in fact I had followed your suggestion to change the back slashes to a single forward slash, but the same problem still occurs.

            To summarise what I think the problem might be:

            1) If I assign the output (i.e. the String "test") of stripper.getTextForRegion("class1") to a String, and then pass this String to the final path, then the program fails.

            2) If I do exactly the same thing, but instead of assigning the output of stripper.getTextForRegion("class1") to a String, I save it to a text file and retrieve it back, then the program succeeds.

            So it should not be a problem of wrong slashes because I'm using the same code both for 1) and 2) above with the small difference of assigning the output to a String in 1) and saving it to a file and retrieve it back in 2).
            • 18. Re: FileNotFoundException error
              EJP
              Exception in thread "main" java.io.FileNotFoundException: C:\Users\MyName\Desktop\test
              .pdf (The filename, directory name, or volume label syntax is incorrect)
              The fact that this error message contains a new line proves beyond a peradventure that there is something wrong with the value returned by the method you are calling.
              • 19. Re: FileNotFoundException error
                994379
                String path = "C://Users/MyName/Desktop/abc.pdf";
                must work, though we should rather use File.separator instead of slashes.
                • 20. Re: FileNotFoundException error
                  alley
                  Yes but if I remove the ".pdf" to test without this new line being created, I still get the FileNotFoundException error:

                  run:
                  Exception in thread "main" java.io.FileNotFoundException: C:\Users\MyName\Desktop\test
                  (The filename, directory name, or volume label syntax is incorrect)
                       at java.io.FileOutputStream.open(Native Method)
                       at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
                       at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
                       at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1138)
                       at org.apache.pdfbox.examples.util.ExtractTextByArea.main(ExtractTextByArea.java:119)
                  Java Result: 1
                  BUILD SUCCESSFUL (total time: 2 seconds)
                  • 21. Re: FileNotFoundException error
                    alley
                    The problem arises when I assign the output of stripper.getTextForRegion("class1") to a String.

                    In fact, when I save it to a text file and retrieve it back (rather than assigning it to a String), the path creates successfully and the program works.

                    I don't think the slashes has anything to do with the problem.
                    1 2 Previous Next