java判断是否为空白文件

Python09

java判断是否为空白文件,第1张

<title判断是否为空白文件</title</head<body<%String path=request.getRealPath(/)out.println(path)FileReader fr=new FileReader(path + \\AtEnd.txt)//建立FileReader对象,并实例化为fr//对FileReader类生成的对象使用read()方法,可以从字符流中读取下一个字符。if(fr.read()==-1)//判断是否已读到文件的结尾{out.print(AtEnd.txt文件中没有数据<br)}else{out.println(AtEnd.txt文件中有数据)}

import java.io.*

public class test

{

    public static void main(String args[]) throws Exception{

        FileInputStream fin=new FileInputStream("F:\\sample.txt")

        byte[] by=new byte[1000]

        int size=fin.available()

        if(size==0){

           System.out.println("文件为空!!")

        }else{

           int len=fin.read(by)

           System.out.println(new String(by,0,len))

        }

    }

}

关键是这一句,这一句能判断文件是否为空