Home > Back-end >  How do I write to a Linux path in Java?
How do I write to a Linux path in Java?

Time:07-18

I'm using java to save a file in Linux but I must be doing something wrong...

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;

import java.io.*;

public class mainClass {
    public static void main(String[] args) throws IOException {

        PDDocument document = new PDDocument();
        PDPage firstPage = new PDPage();
        document.addPage(firstPage);

        try {
            document.save("/home/MyDirectory/mypdf.pdf");
            System.out.println("pdf created");
            document.close();
        } catch(Exception E) {
            System.out.println(E);
        }

    }
}

And I am getting this error.

java.io.FileNotFoundException: /home/MyDirectory/mypdf.pdf (No such file or directory)

I know the problem is to do with the file destination but I'm not too sure. /home/MyDirectory exists but idk. Thanks!

CodePudding user response:

Maybe is missing the user : /home/THE_USER/MyDirectory/mypdf.pdf

  • Related