日期:2014-05-20  浏览次数:20712 次

求助我是一个初学者求高手帮我看一下我这哪儿错啦
package 第十四章.IO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Fileinput {

  public static void main(String[] args) {
  try {
  byte rb;
  byte rba[] = new byte[4], rs[] = new byte[128];
  String s1;
  FileInputStream filein =
  new FileInputStream("D:\\wf1.text");
  rb = (byte) filein.read();
  filein.read(rba);
  filein.read(rs);// 字节流格式只能读到数组
  String s = new String(rs);
  filein.close();
  System.out.println("rb=" + rb + "\nrba[2]=" + rba[2] + "\nrs=" + s);
   
  /*byte b1 = 67;
  byte ba1[] = {30, 40, 50, 60};
  String s2 = "把字符串写入流格式文件";
  FileOutputStream out1 = new FileOutputStream("C:\\wf1.text");
  out1.write(b1);
  out1.write(ba1);
  out1.write(s2.getBytes());//串转换为字节数组才能写入
  out1.close();
  */
  } catch (Exception e) {
  e.printStackTrace();
  }

  }
}


------解决方案--------------------
filein.read();
返回的是一个int 型数值 BYTE是装不下的
------解决方案--------------------
FileInputStream filein =
new FileInputStream("D:\\wf1.text");
你要读取的文件 不存在 你D 盘下是不是没有这个文件呀
------解决方案--------------------
文件没找到,看看对应目录下是不是有对应的文件
------解决方案--------------------
探讨

但必须要有吗
不是如果没有
它自己创建了吗