<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Java 創建只讀文件示例 > 原文: [https://howtodoinjava.com/java/io/how-to-make-a-file-read-only-in-java/](https://howtodoinjava.com/java/io/how-to-make-a-file-read-only-in-java/) 要使文件在 Java 中只讀,可以使用以下方法之一。 使用`Runtime.getRuntime().exec()`的第三種方法是特定于平臺的,因為您會將命令作為參數傳遞給它。 其余兩種方法在大多數情況下都可以正常工作。 如果您想更改 Linux/unix 特定的文件屬性,例如 使用`chmod 775`,則 java 不提供任何方法。 您應使用`Runtime.getRuntime().exec()`來使用第三種方法。 ## 1)使用`java.io.File.setReadOnly()`方法 ```java private static void readOnlyFileUsingNativeCommand() throws IOException { File readOnlyFile = new File("c:/temp/testReadOnly.txt"); //Mark it read only readOnlyFile.setReadOnly(); if (readOnlyFile.exists()) { readOnlyFile.delete(); } readOnlyFile.createNewFile(); } ``` ## 2)使用`java.io.File.setWritable(false)`方法 ```java private static void readOnlyFileUsingSetWritable() throws IOException { File readOnlyFile = new File("c:/temp/testReadOnly.txt"); if (readOnlyFile.exists()) { readOnlyFile.delete(); } readOnlyFile.createNewFile(); //Mark it read only readOnlyFile.setWritable(false); } ``` ## 3)執行本機命令(取決于平臺) ```java private static void readOnlyFileUsingSetReadOnly() throws IOException { File readOnlyFile = new File("c:/temp/testReadOnly.txt"); //Mark it read only in windows Runtime.getRuntime().exec("attrib " + "" + readOnlyFile.getAbsolutePath() + "" + " +R"); } ``` **祝您學習愉快!**
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看