- package myjava;
- import java.io.*;
- public class ReadExample {
- public static void main(String[] args) throws NullPointerException,IOException {
- File file=new File("e:/temp.txt");
- FileReader in = new FileReader(
- new File("src\\myjava\\ReadExample.java"));
- FileWriter out =new FileWriter(file);
- int a;
- out.write("1. ");
- int i = 2;
- while((a = in.read())!=-1){
- if((char)a!= '\n'){
- out.write(a);
- }
- else{
- out.write("\n");
- out.write(i+". ");
- out.write(a);
- i++;
- }
- }
- out.close();
- in.close();
- }
- }
复制代码 以下是我的运行结果,大牛可以帮我进一步改进。谢谢啦。
|