如何用 Java 開啟一個純文字檔案?


你可以使用 File 類訪問純文字。

示例

現場演示

import java.io.File;

public class ReadFile {
   public static void main(String[] args) {
      File f = null;
      String str = "data.txt";

      try {
         f = new File(str);
         boolean bool = f.canExecute();
         String a = f.getAbsolutePath();
         System.out.print(a);
         System.out.println(" is executable: "+ bool);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

輸出

 C:\Users\data is executable: true

更新日期:2020-02-20

273 次瀏覽

開啟你的 職業生涯

完成本課程以獲得認證

開始學習
廣告
© . All rights reserved.