本帖最后由 ifuzhen 于 2014-4-24 16:32 编辑
- import java.io.*;
- class Test
- {
- public static void main(String[] args) throws IOException
- {
- copyfile();
- }
- public static void copyfile()throws IOException
- {
- //BufferedReader bufr =null;
- FileReader fr =null;
- LineNumberReader lnr =null;
- BufferedWriter bufw =null;
-
- lnr =new LineNumberReader(fr =new FileReader("Test.java"));
- bufw =new BufferedWriter(new FileWriter("Testcopy.java"));
- String line=null;
- while((line=lnr.readLine())!=null)
- {
- //System.out.println(lnr.getLineNumber()+":"+line);
- bufw.write(lnr.getLineNumber());
- System.out.println(lnr.getLineNumber());//在控制台是可以正常显示行号的,到了文件中却显示不出来了??
- bufw.write(line);
- bufw.newLine();
- bufw.flush();
- }
-
- }
- }
复制代码 |
|