java IO流中,如何判断一个文本是不是空的?
答案:6 悬赏:50 手机版
解决时间 2021-11-20 14:06
- 提问者网友:寂寞撕碎了回忆
- 2021-11-19 22:15
java IO流中,如何判断一个文本是不是空的?
最佳答案
- 五星知识达人网友:夜风逐马
- 2021-11-19 22:36
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));
}
}
}
关键是这一句,这一句能判断文件是否为空
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));
}
}
}
关键是这一句,这一句能判断文件是否为空
全部回答
- 1楼网友:笑迎怀羞
- 2021-11-20 02:30
File f=new File();
判断下f.length
判断下f.length
- 2楼网友:第四晚心情
- 2021-11-20 01:25
从流里面读取字节,判断是否为空就可以了。
- 3楼网友:杯酒困英雄
- 2021-11-20 01:09
用readline()方法
while(line=in.readLine()!==null){
// 如果不为空,你要进行的读取操作。
}
- 4楼网友:持酒劝斜阳
- 2021-11-20 00:11
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
- 5楼网友:等灯
- 2021-11-19 22:52
先判断它的长度
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯