您的位置:首页 > 其它

文件的输入与输出

2015-11-23 21:06 381 查看
import java.io.*;
import java.util.Scanner;
import java.io.FileOutputStream;
public class Readdata {
public static void main(String[] args) throws IOException{
Scanner sc = null;
try{

String path = "E:/test.txt";
sc = new Scanner(new File("E:/test.txt")); // 从文件中读取数据
File file = new File(path);

if(!file.exists()){

file.createNewFile();
}

else
{
FileInputStream test = new FileInputStream(file);

byte[] byt = new byte[1024];

int len = test.read(byt);

System.out.println("文件的信息是:\n"+new String(byt,0,len));

}
}catch(FileNotFoundException e){
e.printStackTrace();
System.exit(0);
}
sc.close();//关闭操作
}
}


## 结果 ##


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: