- <p>这是我自己写的一个代码,感觉有些麻烦</p><p>import java.io.*;
- class FileTest
- {
- public static void main(String[] args) throws IOException
- {
- method_1();
- method_3();
- }
- public static void method_1() throws IOException
- {
- FileReader fr = new FileReader("demo.txt");
- int num = 0;
- char[] ch = new char[1024];
- while ((num=fr.read(ch))!=-1)
- {
- method_2(num,ch);
- }
-
- fr.close();
- }
- public static void method_2(int num,char...ch) throws IOException
- {
- FileWriter fw = new FileWriter("d:\\demo.txt",true);
- fw.write(ch,0,num);
- fw.flush();
- fw.close();
- }
- public static void method_3() throws IOException
- {
- FileReader fr = new FileReader("d:\\demo.txt");
- int num = 0;
- char[] ch = new char[1024];
- while ((num=fr.read(ch))!=-1)
- {
- sop(new String(ch,0,num));
- }
- fr.close();
- sop("复制成功!!!!!!!!!!!!!");
-
- }
- public static void sop(Object obj)
- {
- System.out.print(obj);
- }
- }</p>
复制代码
|
|