国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Java文件操作

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

 /**
  *
  * 先判斷文件是否存在,然后判斷文件是否為空。
  * 如果存在且不為空,則輸出文件內(nèi)容在控制臺。
  *
  * @author rmouse_2005   
  * @data 2005-10-14  
  * @version 1.0
  */ 

public class Test {

 /**
  *
  * Test類主函數(shù)
  *
  * @param args
  * @throws IO異常
  */
 public static void main(String[] args) throws IOException {
  String path = "h:\\eclipse\\test\\a.txt";
  Test t = new Test();
  if (t.isExist(path)) {
   if (t.isEmpty(path)) {
    System.out.println("success!");
    System.out.println();
    t.getValue(path);
   } else {

    System.out.println("false!");
   }
  } else {
   System.out.println("false!");
  }
 }

 /**
  *
  * 判斷文件是否存在
  *
  * @param file 文件名
  * @return 文件是否存在
  * true - 文件存在
  * false - 文件不存在
  */
 boolean isExist(String file) {
  File f = new File(file);
  if (f.exists()) {
   System.out.println("File is Exist!");
   return true;
  } else {
   System.out.println("File isn‘t Exist!");
   return false;
  }
 }

 /**
  *
  * 判斷文件是否為空
  *
  * @param file 文件名
  * @return 文件是否為空
  * true - 文件為空
  * false - 文件不為空
  * @throws IO異常
  */
 boolean isEmpty(String file) throws IOException {
  FileReader fr = new FileReader(file);
  if (fr.read() == -1) {
   System.out.println("File is Empty!");
   return false;
  } else {
   System.out.println("File isn‘t Empty!");
   return true;
  }
 }

 /**
  *
  * 讀取文件
  *
  * @param file 文件名
  * @throws IO異常
  */
 void getValue(String file) throws IOException {
  FileReader fr;
  fr = new FileReader(file);
  BufferedReader br = new BufferedReader(fr);
  String line = "";
  line = br.readLine();
  while (line != null) {
   String lineNew = "";
   lineNew = line;
   System.out.println(lineNew);
   line = br.readLine();
  }
 }
}

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java中io操作小例子
Java文件操作詳解
文件數(shù)據(jù)的讀/寫
java在指定路徑下創(chuàng)建文件,并寫入文件內(nèi)容
Java 2 實用教程(第5版)耿祥義版 習題十
java對本地日志文件的讀寫
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服