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

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

Related

insert a file into postgres

How do I insert a file that resides in windows in c:\temp\sample.txt
I have tried
insert into lob_file VALUES (5, pg_read_file('c://temp//sample.txt')::BYTEA);
and got
ERROR: could not start file c://temp//sample.txt. No such file or
directory.
Is data base running locally or on a Windows server and you have moved the file to the server. See Docs
The functions shown in Table 9.94 provide native access to files on
the machine hosting the server. Only files within the database cluster
directory and the log_directory can be accessed unless the user is
granted the role pg_read_server_files. Use a relative path for files
in the cluster directory, and a path matching the log_directory
configuration setting for log files.

How to give local system path in ssh?

I'm trying to insert records from local directory path in SSH but it shows "file not found" because it does not recognize the path. But if I give sft directory then it recognise the path.
This is the code:
Local directory path:
./putmsgE1E2.ksh LPDWA123 ABC.GD.SENDCORRESPONDENCE.BATCH.INPUT XPRESSION.TEST /Users/admin/Desktop/important.txt;
and I tried using c:/Users/admin/Desktop/important.txt
SFT Directory:
./putmsgE1E2.ksh LPDWA123 ABC.GD.SENDCORRESPONDENCE.BATCH.INPUT XPRESSION.TEST /abchome/abc123/1.txt;
I have inputs in the txt file in my local directory; I want to poll that files to the server. Hope someone finds a solution. Thanks.
Use the below command on Linux systems:
scp /path/to/your/local/file remoteUser#some_address:/home/remoteUser/Documents

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?

Servlet - Addressing properties files

I have a simple Servlet that needs to pass some properties files to another class.
Properties prop = new Properties();
prop.load(new FileInputStream("/home/user/config.properties"));
Above works fine.
But I can't address the right absolute path in below:
String protocol = prop.getProperty("protocol", "/home/user/protocol.properties");
String routes = prop.getProperty("routes", "/home/user/routes.properties");
MyClass message = new MyClass(protocol, routes, 0);
At the end I receive below from tomcat log:
INFO: Server startup in 3656 ms
java.io.FileNotFoundException: routes.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at com.cc.verticals.Messenger.<init>(Messenger.java:134)
at com.foo.MyClass.<init>(MyClass.java:42)
at com.verticals.cc.util.VerticalUtil.setup(VerticalUtil.java:59)
at com.verticals.cc.util.VerticalUtil.main(VerticalUtil.java:259)
at com.verticals.cc.dao.VerticalDao.<init>(VerticalDao.java:24)
at com.verticals.cc.controller.VerticalController.<init>(VerticalController.java:33)
Line 42 is pointing to the constructor where routes.properties file goes in.
Messenger line 134 points to:
prop.load(new FileInputStream(routesFilename));
Any Idea how to address the properties files and send them as a String parameter? Thanks.
By the looks of it (I prefer if you post the content's of the properties files), there is a property within config.properties such that routes = routes.properties. When you call new file(routes); you get the FileNotFoundException because you are trying to open routes.properties in the current working directory where java was launched (which doesn't exist)
As a side note, you using one property file to reference another property, which is fine but a bit odd or unconventional. Further, you should stick these files in a 'resource' folder to remove absolute paths and gain portability.
Notice that prop.getProperty method cannot throw FileNotFoundException. So that exception must have been thrown earlier on prop.load();
Please make sure that you have opened the permissions on the file. Open a terminal and issue following command:
$ chmod 777 /home/user/routes.properties
$ chmod 777 /home/user/protocol.properties

Java can't find Mapped Network Drive under Windows 2008 R2

We try to access file under some folder, in WinXP, that folder can be local disk or mapped network drive. But when we change our program to run on Windows 2008 R2, it can access local disk, but no mapped network drive. The mapped network drive had checked for login with proper user.
We try in explorer, the mapped drive can Read/Write as we wished, but Java just show "Folder doesn't exist"
Here is our code, any suggestion will be appreciated.
#import java.io.File;
...
File folder = new File(folderPath);
if(!folder.exists()){
// do something
log.debug("Folder doesn't exist");
} else {
// do something else
}
...
Mapped drive may be not found for current user. For example, if you start some jar executable as administrator it may not find network drive which was mapped under user credentials. In a word, it can be a user identification problem.
I've had this problem with Windows Server 2008 64bit and had no luck using a path with network letter (e.g. X:\EXAMPLE\PATH). Using full network paths (\\SERVER\EXAMPLE\PATH) was ok. The path should be accesible to the user who will run the program.

Categories