Getting an exception when trying to rename a file within Spark application. Permission denied - new file name. The same thing works good with the spark-shell with by the same user. P.S. The path is mounted to S3.
The code:
import org.spark_project.guava.io.Files
Files.move(new File(oldfilename), new File(newfilename))
The exception:
java.io.FileNotFoundException: /path/new_file_name.csv (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at org.spark_project.guava.io.Files$FileByteSink.openStream(Files.java:223)
at org.spark_project.guava.io.Files$FileByteSink.openStream(Files.java:211)
at org.spark_project.guava.io.ByteSource.copyTo(ByteSource.java:203)
at org.spark_project.guava.io.Files.copy(Files.java:436)
at org.spark_project.guava.io.Files.move(Files.java:651)
Expectations: file renamed
java.io.Fileis obsolete (and one of the reasons it is obsolete, is bad error messages, so relevant here). Usejava.nio.file.Pathobjects andjava.nio.file.Files.move(no need for guava) instead to possibly get a more detailed error message.Files.move(neither guava's nor java.nio's) will make them for you. And, of course, check the permissions on that folder. The error seems to occur on the creation part, not on the 'remove the old one' part.