FileInputStream,FileOutputStream,FileWriter,FileReader
很简单,你可以这样做,他的基础就是,你首先new一个文件流,也就是一个通往文件的通道
就像用自来水要水管一样。
FileInputStream fis=new FileInputStream();
然后,你把水管打开,就可以读文件了(水就来了)
FileReader fr=new FileReader(fis);// <=======括号里的参数就是在铺好的水管以后打开它,并依靠它运输水。呵呵,不知道这样子讲你明白么?
不明白的话,可以跟贴接着问

解决方案 »

  1.   

    楼上讲的很清楚,建议仔细研读JAVA书籍,到处都是的,实际上,JAVA的IO,是流的,分为字符流和字节流,掌握了字节流就OK了,字符流只是为了方便操作字符才存在的
      

  2.   

    Java.io主要包括三个类和接口组
    1、 建立数据流的类
    2、 用于序列化的类和接口
    3、 用于文件的类和接口字节输入流的超类     InputStream
      字节输出流的超类     OutputStream
      
      字符输入流的超类    Reader
      字符输出流的超类    Writer  字节流向字符流转换器
      InputStreamReader 从一个字节流读取字节,然后把它转换为字符
      OutputStreamWriter 把字符转换为一个字节编码,然后把它写进字节流文件
    FileInputStream 和FileOutputStream对 文件的字节进行读写操作。
    FileReader 和 FileWriter 对文件的字符进行读写。
    RandomAccessFile 对文件的内容进行随机访问。对文件读写的操作:
    //1.以行为单位从一个文件读取数据
    BufferedReader in = new BufferedReader(new FileReader("F:\\nepalon\\TestIO.java"));
    String s, s2 = new String();
    while((s = in.readLine()) != null)
    s2 += s + "\n";
    in.close();// 输出到文件
    try{
    BufferedReader in4 =new BufferedReader(new StringReader(s2));
    PrintWriter out1 =new PrintWriter(new BufferedWriter(new FileWriter("F:\\nepalon\\TestIO.out")));
    int lineCount = 1;
    while((s = in4.readLine()) != null)
    out1.println(lineCount++ + ":" + s);
    out1.close();
    in4.close();
    }
    catch(EOFException ex){
    System.out.println("End of stream");
    }
      

  3.   

    import java.io.*;public class WriteFileDemo {
      public static void main(String[] arg) throws IOException {
        byte[] somebyte = {
            'a', 'b', 'c'};
        String hello = "hello";
        FileOutputStream out = new FileOutputStream("c:/data.tmp");
        if (out != null) {
          System.out.println("开始写入文件");
          out.write(somebyte);
          String str = new String(somebyte, 0);
          System.out.println("输出字节:" + somebyte + "或者输出字符串:" + str);
          for (int i = 0; i < hello.length(); i++) {
            out.write(hello.charAt(i));
          }
          System.out.println("输出字符串hello:" + hello);
          out.close();
        }
      }
    }
      

  4.   

    http://www.j2medev.com/Article_Class.asp?ClassID=5搂主有必要把IO系统理清楚   参考一下这几篇文章把
      

  5.   

    import java.io.FileInputStream;
    import java.io.FileOutputStream;/**
     * @author 崔占民
     *
     * To change the template for this generated type comment go to
     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
     */
    public class copy
    {
    final private static int INT_READLEN = 10240; public static void main(String[] args)
    {
    if (args.length == 0 || (args.length == 1 && !args[0].equals("/?")))
    {
    System.out.println("command syntax is invalidity!");
    return;
    }
    else if (args[0].equals("/?"))
    {
    System.out.println("copy SrcFile DesFile");
    System.out.println("SrcFile: Source File.");
    System.out.println("DesFile: destination File.");
    return;
    }
    copy cpy = new copy(args[0], args[1]);
    } copy(String aStrSrcFile, String aStrDesFile)
    {
    if (aStrSrcFile.equals("") || aStrDesFile.equals(""))
    {
    System.out.println("please input SrcFile and DesFile!");
    System.out.println("copy SrcFile DesFile");
    return;
    } FileInputStream in = null;
    FileOutputStream out = null;
    try
    {
    int bytes = 0;
    byte[] bteFile = new byte[INT_READLEN];
    in = new FileInputStream(aStrSrcFile);
    out = new FileOutputStream(aStrDesFile); while ((bytes = in.read(bteFile)) != -1)
    {
    out.write(bteFile, 0, bytes);
    }

    System.out.println("File Copy finished!");
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    }
    finally
    {
    try
    {
    in.close();
    out.close();
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    return;
    }
    }
    }
    }//这是类似DOS的COPY命令的一个例子,你看看吧 ~~~~~
      

  6.   

    FileReader(File file) 
              Creates a new FileReader, given the File to read from. 
    FileReader(FileDescriptor fd) 
              Creates a new FileReader, given the FileDescriptor to read from. 
    FileReader(String fileName) 
              Creates a new FileReader, given the name of the file to read from.