Java操作txt文件

不废话,直接上代码:

java中生成txt文件:

<%

       String text = request.getParameter("text"); 

       String readStr="";  //用于一直存储

       String read=""; //用于临时读取

        FileReader fileread;

        BufferedReader bufread;

        try {

            fileread = new FileReader("C:\\Documents andSettings\\Administrator\\Workspaces\\MyEclipse8.6\\TaskTwo\\WebRoot\\b.txt");

            bufread = newBufferedReader(fileread);

            try {

                while ((read = bufread.readLine()) != null) {

                    readStr = readStr +read;

                }

            } catch (IOException e) {

                e.printStackTrace();

            }

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        }

%>

 

java读取txt文件

    String text = request.getParameter("text"); 

       String readStr="";  //用于一直存储

       String read=""; //用于临时读取

        FileReader fileread;

        BufferedReader bufread;

        try {

            fileread = new FileReader("C:\\Documents andSettings\\Administrator\\Workspaces\\MyEclipse8.6\\TaskTwo\\WebRoot\\b.txt");

            bufread = newBufferedReader(fileread);

            try {

                while ((read = bufread.readLine()) != null) {

                    readStr = readStr + read;

                }

            } catch (IOException e) {

                e.printStackTrace();

            }

        } catch (FileNotFoundException e) {

            e.printStackTrace();


posted on 2011-11-08 15:09  java课程设计例子  阅读(177)  评论(0编辑  收藏  举报