首页 > 学院 > 开发设计 > 正文

很简短的几句就能访问文件输出文件

2019-11-18 13:15:45
字体:
来源:转载
供稿:网友

  import java.io.*; /*引用java.io包下所有类*/
  
  public class test4 /*class test4
  {
  public static void main(String[] args) throws IOException
  {
  InputStream is =new FileInputStream("test2.txt"); /*新建立is对象
  int n,ch; /*定义变量
  for(n=0;(ch=is.read())!=-1;n++) /*循环输出
  {
  System.out.PRint((char)ch); /*从屏幕上打印出文件内容
  }
  System.out.println();
  System.out.println("/n-----------------------");
  System.out.println("一共有"+n+"个字符"); /*显示字符的个数
  }
  }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表