How does Windows set up files to be read-only or hidden?
(1) Windows settings file read-only
/*** * is set to read-only * @param filePath * @return */public static int readOnly (String filePath) {if (new File (FilePath). Exists ()) {Pro Cess p=cmdutil.executecmd ("attrib" +filepath+ "+r"); try {p.waitfor ();} catch (Interruptedexception e) { E.printstacktrace (); return systemhwutil.negative_one;} return P.exitvalue ();} Else{return Systemhwutil.negative_one;}}
(2) Remove file read-only properties
/*** * is set to writable * @param filePath * @return */public static int removereadonly (String filePath) {if (new File (FilePath). Exists ( ) {Process p=cmdutil.executecmd ("attrib" +filepath+ "-R"), try {p.waitfor ();} catch (Interruptedexception e) { E.printstacktrace (); return systemhwutil.negative_one;} return P.exitvalue ();} Else{return Systemhwutil.negative_one;}}
(3) Set file hiding
/*** * Applies to Windows systems only, calls local commands <br> * hide:attrib ". Mqtt_client.properties" +h<br> * show:attrib ". mqtt_client . Properties "-H * @param filePath * @return */public static int Hide (String filePath) {if (new File (FilePath). Exists ()) {Proc ESS p=cmdutil.executecmd ("attrib" +filepath+ "+h"); try {p.waitfor ();} catch (Interruptedexception e) { E.printstacktrace (); return systemhwutil.negative_one;} return P.exitvalue ();} Else{return Systemhwutil.negative_one;}}
(4) Remove file hidden properties
/*** * Applies to Windows systems only, calls local commands <br> * hide:attrib ". Mqtt_client.properties" +h<br> * show:attrib ". mqtt_client . Properties "-H * @param filePath * @return */public static int show (String filePath) {if (new File (FilePath). Exists ()) {Proc ESS p=cmdutil.executecmd ("attrib" +filepath+ "-H"); try {p.waitfor ();} catch (Interruptedexception e) { E.printstacktrace (); return systemhwutil.negative_one;} return P.exitvalue ();} Else{return Systemhwutil.negative_one;}}
(1) (2) (3) (4) Methods of dependence :
public static process Executecmd (String command) {process p = null; try {p = runtime.getruntime (). EXEC (cmd_short + command); } catch (IOException e) {e.printstacktrace (); } return p; }
Description :
The value of the Cmd_short is: "CMD/C"
The value of Systemhwutil.negative_one is-1
(5) Determine if the file or directory Subfilestr exists in the PARENTFOLDERSTR (directory)
/*** * To determine if the parent directory Parentfolderstr has a file subfilestr (or directory) * @param parentfolderstr * @param subfilestr * @return: Returns NULL, indicating that there is no */public static File subfileexist (String parentfolderstr,string subfilestr) {if (!parentfolderstr.endswith ( File.separator)) {parentfolderstr+=file.separator;} File Subfolder=new file (parentfolderstr+subfilestr), if (Subfolder.exists ()) {return subfolder;} Else{return null;}}
Description : Returns the absolute path to the subdirectory if it exists, or null if it does not exist.
Depending on the jar see attachment
This article is from the "Whuang" blog, make sure to keep this source http://huangkunlun520.blog.51cto.com/2562772/1599339
The settings file is read-only in Java windows