The settings file is read-only in Java windows

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.