File created from within my Eclipse does not have read permissions - java

A weird question:
I am running eclipse on windows and I am trying to open a file with a hard coded path:
String inputFile = "C:/temp/abc.txt";
File folder = new File(inputFile );
When I run this I get error:
java.io.FileNotFoundException: C:/temp/abc.txt (The system cannot find the file specified)
I have local admin rights on this windows 10 machine. I have tried running Eclipse as a Administrator but it doesn't resolve the issue.
The only way I can get by is if I traverse to C:/temp/ in cygwin and do a chmod 777 * . Then my program is able to open the file okay.
The work around should be fine if I was just reading a simple file but I am also creating files from within my java project which it does successfully create but then when it comes to reading them it fails.
myFile.setReadable(true); // doesnt work either.
Is this some sort of windows permissions issue ? Could it be that cygwin has taken over some admin rights on the file system? I have tried stopping it but the issue persists. Or is this an eclipse setting?
Many Thanks,
-A

It was a windows permissions issue.
Right click on the folder -> Properties -> Security -> Edit -> Add -> Everyone.
I dont understand why I need to add every one if I am the local admin and I launched eclipse but frankly I dont care about the bizarre world of windows.
Thanks to all those who tried helping.
Cheers

check this.
Permission Denied: File Creation in Java
https://www.mkyong.com/java/how-to-set-the-file-permission-in-java/

Related

re install Jdk1.6 in windows 7?

I have installed jdk1.6 in E: drive of windows 7.I developed a simple .java file and try to run it through the command prompt using "javac" but it says javac is not recognized as internal or external command.So i checked just by running java it runs fine .so I thought that i should uninstall that jdk and reinstallit but i am getting windows 1723 error
opened a control panel and tried to remove jdk from there but got this "Error 1723.There is problem with this Windows Installer package.A DLL required for this install to complete could not be run.Contact your support personnel or package vendor"
to be able to run javac from the command line, you need to add the path to javac to the PATH environment variable.
It looks like the 1723 error describes a problem with the installer itself. I would follow the advice from Microsoft Answers and Oracle to fix the installation. A correct install of Java should add the necessary entry on the Windows PATH. Make sure you open a new DOS (or Command) window after installation otherwise the amended PATH might not be picked up.
Probably,you are facing the below issue: https://forums.oracle.com/forums/thread.jspa?threadID=2213081. You can use ccleaner to uninstall all the instance of jdk/jre.The issue is happening due to interrupting in installing/uninstalling.If ccleaer is not solving your problem registry cleaning is the only option as shown on the above link.
You probably have java.exe on your \windows\system32 folder... And since this folder is on the path env var it got confused. Try to delete this/these java*.exe files from \windows\system32 folder.
If you encountered a problem with Java error 1723 when you try to reinstall Java.
It may occur when you delete the Java directory by error
_ Go to your Microsoft Event Viewer you'll see one error line like this
Event viewer
_ Then copy an Java bin directory from an other server to have back the lost dlls in the directory mentioned in the events viewer
_ finally reinstall Java
Hope it helps
I have used Microsoft utility(fix-problems-that-block-programs-from-being-installed-or-removed) to resolve this error it saved me doing manual work and it is safe also :
https://support.microsoft.com/en-us/help/17588/fix-problems-that-block-programs-from-being-installed-or-removed

JAR issue on Windows 2003

I have an application (myapplication.jar) running on Windows 2003. The application was running fine few days back on this server.
I am using a bat file to execute the Jar applicatin, for some reason it stopped working on it and I am unable to find the why?
If I copied the same folder to another server where JRE is already installed it works without an issue.
Cansome suggest me how do I find what is the issue. I have already checked the file type association, delete the temporary files (java cache and temporary files in windows)
Thanks in advance!!
Without any log, exception or stack trace it will be impossible to know what is causing the problem. Open the bat file in an editor and add at the end of line that starts with:
java -jar yourProgramBundledInA.jar > yourApp.log
this is going to redirect the console to yourApp.log file. Save the bat, run it and then look up the content of yourApp.log. There should be a clue why the application is failing.

Mac Java Path Issues with trying to run Android SDK

I'm trying to run the android tool from command line and I keep getting
sdkmanager.jar not found
I've seen a few other questions with this, but none had a clear answer on how to fix it. I believe it's a path problem. It seems obviously a path problem. But how do you change the path in Mac?
I'm an experienced windows user and have always had to install java instead of it coming with the software updates. I even downloaded the 1.7jdk preview port they have for mac that's still in beta.
I just don't know how to change the path so it works. The other person who posted this issue added a EXPORT PATH=/somedir/android-sdk/:$PATH to her .bash_profile but there was no response as to whether it worked. I've tried it. It doesn't, and I wouldn't expect it to because there's no sdkmanager.jar anywhere in the android-sdk-macosx they give you.
Every tutorial on android I've found using Mac has come with ALOT more files than the current sdk you download from android does. I have two empty addon/platform directories and a tools directory with scripts in them. No jar files or anything else.
Please help!
today I fixed this :-) on Mac Lion (server):
1- open Terminal
2- Type cd ~ to go to your home directory ( you will be there by default)
3- Type touch .profile to create a hidden file named profile
4- Type open -e .profile this will open the file you created in TextEdit
5- In the file, type export PATH=${PATH}:FULL_PATH_WHERE_ANDROID_SDK/android-sdk-mac_86/platform-tools
FULL_PATH_WHERE_ANDROID_SDK: where is sdk, don't forget / before, so it will be i.e.
/users/mmm/sdk
6- save file
7- exit TextEdit
8- quit Terminal, and Relaunch Terminal
9- Now type again : adb devices if you get
>List of devices attached
So you did it successfully ..
Good luck
It should be Export PATH=/somedir/android-sdk/:$PATH. This will append the android-sdk dir to the beginning of path. The example you posted is not exporting any variable.

mkdirs not working in windows 7

I made a small java app that copies a directory from a CD to the HD. I made the program using Windows Vista and it worked, but when i ran it in Windows 7, it fails.
The main problem is that a folder inside the Program Files folder needs to be created.
I used DestinationFolder.mkdirs(), but it fails creating it
This is the java code:
public void Install_App()
{
File srcFolder = new File(System.getProperty("user.dir") + "\\WINDOWS");
File destFolder = new File("C:\\Program Files\\test1\\test2\\");
if (srcFolder.exists())
{
try{
if(!destFolder.exists())
{
destFolder.mkdirs();
}
copyFolder(srcFolder,destFolder,1);
}catch(IOException e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
error=true;
System.exit(0);
}
} else
{
JOptionPane.showMessageDialog(null, "Error. Source Directory doesn't exist.");
error=true;
};
}
... and then there is a copyfolder function that copies the files with inputstream and outputstream.
The problem is that the folder is never created. My login user is an administrator. And as i said, it worked in Vista.
Could you help me, please?
Thanks.
The thing is that i created this app in java to run it in Windows and Mac.
In Windows it should autorun with and autorun.inf like this:
[autorun]
OPEN=java_app.bat
then this bat will run this:
#echo off
start javaw -jar "java_app.jar"
EXIT
so how can i modify it to run it as administrator automatically?
The main idea of this java app is simplify the process of install & use an external application no matter which OS are you using. If I have to ask the user to run it as admin it will loose it's sense (of been simple of use).
I am guessing you are running your code as regular user.
Writing into Program Files directory as a regular-user is by default blocked by UAC under Windows 7. That's why your Java code fails to create directories.
Try running your Java code from a privileged shell. You can have one by Start > [type cmd] > [right-click on 'cmd.exe' and select "Run as administrator"]. Now, run your compiled code with java -jar or java -classpath from the administrator command prompt. It should work now.
Automating the UAC prompt:
You need to create a manifest file as described in detail at [1] and [2] to let Windows/UAC know that your program would need elevated privileges.
Also check this [3] utility called elevate that would spawn your program as child process while handling the UAC permission requests all being made from the parent (elevate) program itself.
[1] [http://msdn.microsoft.com/en-us/library/aa511445.aspx][2]
[2] [http://msdn.microsoft.com/en-us/library/bb756929.aspx][3]
[3] [http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/elevate-a-process-at-the-command-line-in-vista.aspx][4]
This is all the permission problems. I have the same problem on my machine. Nothing is wrong with your java code. I tried to create folder using command line and got "Access Denied".
C:\Users\alexr>mkdir "C:\Program Files\mytest"
Access is denied.
So, the solution is whether to create folder in other location or run as administrator. As #Alex K. aready said, refer to this post to learn how to get such permissions.
Windows 7 Create Folder in "Program Files" failing in C# code even thought I have admin rights!
You do not have the proper privileges to create directories in Program Files. You must start the application with administrative privileges.
An important thing to learn is that when you are developing your applications you should never write them to save/modify data inside Program Files; instead they should either write to AppData our My Documents.
Modifying files in Program Files has been severely deprecated ever since Windows Vista, and even earlier than that. You should try and follow this rule from the start, or it means headaches to rewrite your entire application if you ever want to publish it online.

Java is not working in my PC

I had installed Java in my PC and it was working perfectly. Suddenly something went wrong and now I m not able to open swing applications and its showing the error 'Java not found'. But I can run the Eclipse IDE which also needed Java to run. So I decide to reinstall the Java, but when I tried to uninstall the Java it shows the Error 1723 - There is a problem with this Windows Installer Package. So I have installed a new JDK in another location and set the PATH. Still I am not able to run the Swing application.
Can anybody help me on this?
How are you running your swing application?
If it's from the command line like java mySwingApp and you're getting java not found then your PATH isn't set properly. Make sure that the java/bin directory is on your PATH not just the top level directory. You can test your PATH by just typing java in a console window - it should print the java help page.
If you're not running from a terminal like above, then you may need to set a JAVA_HOME environment variable which points to your java installation folder. Here's a tutorial on setting JAVA_HOME
Setting JAVA_HOME
Hope this helps,
Will
This is close to jakob's answer, about trying to get your Java install setup correctly again, just with a little more detail.
I had a similar problem on my Windows 7 box where I was trying to uninstall Java and do a clean install of a newer version. Something got messed up and I would get the 1723 error message during the uninstall and attempted reinstall. Here's information about how I was able to fix the problem, and maybe this will help you:
Look at the log files for the uninstall/reinstall. On Windows 7 they can be found at c:\users\username\AppData\Local\Temp\
The java_install.logdidn't show any extra information, but I had several MSI##### log files that contained error messages about the failed uninstall. The message was: Error 1723.There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor. Action UninstallJRE, entry: MSIUninstallJRE, library: C:\Program Files\Java\jre6\bin\regutils.dll
There was indeed no regutils.dll file, and not even the bindirectory was there. So I copied over a regutils.dll file from another computer, ran the uninstaller, and it worked. Then the new clean install of Java also worked.
So take a look at your logfiles and hopefully that will give you more detailed information about the 1723 error.
This usally happens when you delete Java files manually.
If you try to uninstall Java and it fails, it generates a log file.
Should be in C:\Users[Username]\AppData\Local\Temp
Almost at the end the missing file(s) can be found.
Try to copy that file(s) from a working installation to your computer.
Then you should be able to uninstall your Java and install a new version.

Categories

Resources