 $37.50.
Premium members get this course for $329.00.
Premium members get this course for $12.50.
Premium members get this course for $148.75.
Premium members get this course for $79.20.
Like some other people commented:
1) you could use your own JNI function;
2) execute some OS specific command (i.e. chmod in *nix).
More info:
invoke attrib +R <filename>
do your stuff
invoke attrib -R <filename>
or in Unix
invoke chmod +r <filename>
do your stuff
invoke chmod -r <filename>
File file = new File("textFile.txt");
// Append your data
file.setReadOnly();
ucero007
With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.
I want to do appending from Java class(Not in command line or not through JNI). Since the application is Java, Target Environment requirement is both Windows and Solaris.
"File" setReadOnly() method makes the file Readonly first time. I tried it before itself but subsequent time it will through Security Exception if we try to append to same File.
Is there any way during subsequent times we change the file permission, append the contents to same file and set it as Read Only again.
Best Regards,
Prasanna
Best Regards,
Prasanna
This is why using native methods is not a good solution. It would be better to detect the OS and do it via the shell as mentioned. The same code could then be use for each OS.
When u mentioned "attrib" and "chmod", unfortunately I didnt get the meaning as i also know them as commands and i have used them 100 times in Solaris (chmod).
I was thinking JNI as the option. Today I tried it with "Runtime" class, "exec()" method and I could do it. I dont know whether its a correct way to do. I am handling the Security, IO Exception anyway.
Runtime r = Runtime.getRunTime();
r.exec("attrib -R sample.txt"); // For Windows
or
r.exec("chmod 777 sample.txt"); // For Solaris
Any suggestions on the above approach,
Best Regards,
Prasanna
>>unfortunately I didnt get the meaning as i also know them as commands
Well they *are* commands. I think maybe I didn't make myself absolutely clear. I meant for these commands to be executed by the Runtime class. First, though, you'd have to do something like:
public class OsDetect {
public static void main(String[] args){
String os = System.getProperty("os.nam
if(os.indexOf("WINDOWS") <= 0){
// You're windozing
}
else {
// You could be dealing with something *serious*!
}
}
}