文件拷贝<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.io.*" %>
<%
int bytesum=0;
int byteread=0; 
file://读/到流中
InputStream inStream=new FileInputStream("c:/aaa.doc");
FileOutputStream fs=new FileOutputStream( "d:/aaa.doc");byte[]  buffer =new  byte[1444];
int length;
while ((byteread=inStream.read(buffer))!=-1)
 {
   out.println("<DT><B>"+byteread+"</B></DT>");
   bytesum+=byteread;
   System.out.println(bytesum);
   fs.write(buffer,0,byteread);
 } 
inStream.close(); 
%>

解决方案 »

  1.   

    import java.io.*;public class fileTest2
    {
     public static void main( String[ ] args ) throws IOException
     {
        FileInputStream fis1 = new FileInputStream( "1.txt" );
        int a = fis1.read( );
        while( a != -1 )
        {
           System.out.println( (char) a );
                           a = fis1.read();
        }
        fis1.close( );
     }
    }改成上面那样。
      

  2.   

    import java.io.*;public class test
    {
       public static void main( String[ ] args ) throws IOException
       {
          FileInputStream fis1 = new FileInputStream( "1.txt" );
          int a = 0;
          while((a=fis1.read( )) != -1 )
          {
              System.out.println( (char) a );
          }
          fis1.close( );
       }
    }
      

  3.   

    这么写
    while((a = fis1.read())!=-1)
      

  4.   

    在System.out.println( (char) a );下面加上一句:
    a = fis1.read();就行了。
      

  5.   

    int a = fis1.read( );要放在循环里.
      

  6.   

    没注意啊!如果我想打印出来的格式是和文件里的格式一样,该怎么改?!
    这样的结果是
    a
    b
    c
    ..而我想是
    abcd
      1234谢谢!
      

  7.   

    while((a = fis1.read())!=-1)
      

  8.   

    没注意啊!如果我想打印出来的格式是和文件里的格式一样,该怎么改?!
    这样的结果是
    a
    b
    c
    ..而我想是
    abcd
      1234谢谢!
    请教!!!!!!!!!!!!
      

  9.   

    /*
     * BufferReadLine.java
     * 
     * Created by ww on 2004/07/02
     *
     */import java.io.*;public class BufferReadLine {    public void FileRW(String fileRead) throws IOException {
            String str = null;        File fin = null;
            File fout = null;
            FileReader fr = null;
            BufferedReader inbr = null;
            String keyWords = null;
            fin = new File(fileRead);        if (fin.exists() && fin.isFile() && fin.canRead()) {
                fr = new FileReader(fin);
                inbr = new BufferedReader(fr);
            }
            else {
                System.err.println(
                    fileRead + " not exists or it not a file or it can't read");
                System.exit(-1);
            }        System.out.println("----------------------------------------------");
            do {
                str = inbr.readLine();
                if (str != null) {                System.out.println(str);
                }
            }
            while (str != null);
            //close file
            inbr.close();
            fr.close();
        }    public static void main(String[] args) {
            if (args.length != 1) {
                System.err.println("use: java Main <fileNameRead>");
                System.exit(-1);
            }
            BufferReadLine filedemo = new BufferReadLine();
            try {
                filedemo.FileRW(args[0]);
            }
            catch (IOException e) {
                System.out.println("file read or write error");
                System.exit(-1);
            }
        }
    }
      

  10.   

    执行时 java BufferReadLine fileName