RSS
热门关键字:  下载  cms  模版  开源  dedecms
当前位置 :| 主页 > 站长学院 > JSP教程 >

java读文件

来源:互连网 作者:佚名 时间:2006-04-12 Tag: 点击:
/* Readfile.java
读取文件的内容,并将原样输出至屏幕上
使用方法:java Readfile 文件名
*/

import java.io.*;

public class Readfile
{
public static void main(String[] args)
{
byte[] buff = new byte[1024];
boolean cont = true;
FileInputStream infile = null;

// 生成对象infile 准备读取文件
try
{
infile = new FileInputStream(args[0]);
}
catch (FileNotFoundException e)
{
System.err.println("没有找到文件");
System.exit(1);
}

while (cont)
{
try
{
int n = infile.read(buff); // 从文件读取数据
System.out.write(buff, 0, n); // 写入System.out中
}
catch (Exception e)
{
cont = false;
}
}

try
{
infile.close();
}
catch (IOException e)
{
System.err.println("文件错误");
System.exit(1);
}
}
}
上一篇:java写文件
下一篇:文件上传下载
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
相关文章