|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
/* 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的解释器设计模式 下一教程: Java套接字编程(下)(2) 您可以阅读与"java读文件"相关的教程: · JAVA读文件 · Java IO学习基础之读写文本文件 · 用java读写ini配置文件 · JAVA 的 HTTP 文件队列下载 · 从JAVA档案(JAR)中读取文件 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |