Where can I store data as a System Service? - java

I programmed a system-service and it tries to create a directory to save some data. The dir that I chose was /.myServiceData.
When I try to run it I get this error: mkdir /.ethNode: read-only file system.
Where can I store my data in the system-service on android?
-UPDATE:
I now tried to getFilesDir() in the system-service, and it also throws an error:
Caused by: java.lang.RuntimeException: No data directory found for package android

Related

Java - Newly created file on smb share has no user, no group

I mounted a SMB share via fstab:
//IP_SERVER/public /home/sl/images_server cifs username=USER,passwd=PASSWD 0 0
I want to create some new files in /home/sl/images_server. The folder has the mod 777 and the user and group sl.
When I try to save a file via Java I get this error:
java.io.FileNotFoundException: /home/sl/images_server/test.jpg (Permission denied)
I use the following code to write the image:
ImageIO.write(ImageIO.read(SOURCE_FILE), "jpg", new File("/home/sl/images_server/test.jpg"));
After I executed the Java command I see a newly created file in the folder with nobody as user, nogroup as group and '-rw-r--r--' as mod.
What is neccessary to save a file in this folder.
Ok, the problem has nothing to do with Java. It was just my samba server which wasn't configured well.
See this for more informations.
https://askubuntu.com/questions/97669/i-cant-get-samba-to-set-proper-permissions-on-created-directories

HDFS copyToLocalFile throws java.io.IOException: Mkdirs failed to create file

I am trying to copy the file from HDFS to Local linux file system using Hadoop FileSystem class.
I have access to create folder in the path where i am trying to copy, i checked using mkdir command.
Also i tried using shell command hadoop fs -copyToLocal hdfsFilePath localFilepath it was working.
I am running this on YARN Cluster.
I tried below approaches, but i am getting the java.io.IOException: Mkdirs failed to create file:/home/user error.
Error log:
16/01/14 01:09:36 ERROR util.FileUtil:
java.io.IOException: Mkdirs failed to create /home/user (exists=false, cwd=file:/hdfs4/yarn/nm/usercache/user/appcache/application_1452126203792_8862/container_e2457_1452126203792_8862_01_000001)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:442)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:428)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:908)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:889)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:786)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:365)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:338)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:289)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1970)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1939)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1915)
at com.batch.util.FileUtil.copyToLocalFileSystem(FileUtil.java:66)
at com.batch.dao.impl.DaoImpl.writeFile(DaoImpl.java:108)
at com.batch.JobDriver.runJob(JobDriver.java:79)
at com.batch.JobDriver.main(JobDriver.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:480)
Actually i am passing localFilePath as /home/user/test, but i am getting the error like failed to create file:/home/user
fs.copyToLocalFile(hdfsFilePath, localFilePath);
fs.copyToLocalFile(false, hdfsFilePath, localFilePath, true);
This week i faced the same thing, problem was that i was deploying the job in cluster mode, therefore the machine where the job was going to run did not have that directory created. Is it possible you are deploying the job in cluster mode? If so, try deploying it in client mode (the output directory has to exist though)
For anyone looking for this exact error, but maybe not from YARN:
I had this exact error when trying to run org.apache.hadoop.fs.FileSystem.copyToLocalFile on my local (Mac) machine, with local FS configured using the job.local.dir attribute.
This was the exception:
java.io.IOException: Mkdirs failed to create file:/User/yossiv/algo-resources/AWS/QuerySearchEngine.blacklistVersionFile (exists=false, cwd=file:/Users/yossiv/git/c2s-algo)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:456)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:441)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:928)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:909)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:806)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:368)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:341)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:292)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:2066)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:2035)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:2011)
What fixed it was to change job.local.dir to be under the current directory , which is listed in the exception text after cwd=, In my case that's /Users/yossiv/git/c2s-algo.
Broke my head two days over this, hope this helps someone.

Access php temp file with java

I like to access an uploaded file which is temporarily stored in /tmp via php.
If I try to access it using the tmp_name from php which is the path I get this error:
java.io.FileNotFoundException: /tmp/php5UY3Ag (Permission denied)
The file is there. Otherwise I would get this error:
java.io.FileNotFoundException: /tmp/php5UY3Ag (No such file or directory)
I'm using the PHP JAVA Bridge to hand over the path.
Java is running under apache tomcat and php under the apache web server.
What do I have to do to get this working?

Ask permission from the user to write files

I have a web application that has the feature to upload PDF which is done by the following process:
Create a folder on user's local path ( C:/resource/pdf/ )
Write the PDF file inside the folder.
On my local(running on eclipse/tomcat) it can write the files directly but on the web I actually getting an error:
java.io.FileNotFoundException: C:\resource\pdf\Daily News.pdf (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
...
I'm using Spring MVC if it is related.
Is there a way to ask the user for a permission to write files in their local?
I am assuming you use a File object in your code; if so you can just do this:
File folder;
// set directory and everything
// create folder
folder.setWritable(true, true);
Then you can check if you can write with this:
write = folder.canWrite();
System.out.println(write);

How to get a path of a folder in cloudera?

Im trying to run a my code in java using hadoop but I get an error of the path of the file
scanner1 = new Scanner(new File("/home/cloudera/pos.txt")); //Path
The error message that I get is:
Status : FAILED
java.io.FileNotFoundException: /home/cloudera/pos.txt (Permission denied)
The "Permission denied" in the error message indicates you don't have read access to the directory. Which user is running the java code, your personal user or the cloudera? To fix, you should either make the data readable for your user, move it to a common location that is globally readable, think /usr/local, or run your code as the cloudera user. Also, is this in HDFS or on the local filesystem?

Categories