使用io包中的类实现该功能:把一个文件中的内容复制到另一个文件中。
FileReader BufferedReader
FileWriter BufferedWriter
String   StringBuffer
随机生成10个点坐标,将它们的坐标值以二进制的形式写入d:\test_10.dat中,然后可以用ultraedit打开该文件查看内容。     
     提示:
    1. 创建类Point,定义点坐标(x, y),同时利用构造方法生成点对象,坐标值为随机值。
    2. 以二进制的形式写入某文件中,使用io包中的FileOutputStream和DataOutputStream。
这两个怎么写..我对这部分不是很熟悉..谢谢了```

解决方案 »

  1.   

    第一个问题也可以这么解决,用复制文件的方式
    --------------------------------------
    /**
     * project_name: Test
     * package_name: csdn_Test_20071126
     * package_declaration: package csdn_Test_20071126;
     * filename: RemoveFileTest.java
     * author: yuhaiming
     * date: 2007-12-4
     */
    package csdn_Test_20071126;
    import java.io.*;
    public class RemoveFileTest {
    /**
     * 主函数处理
     */
    public static void disposal(){
    File oldFile = new File("test.txt");
    System.out.println(oldFile.getAbsolutePath());
    File newFile = new File("testResult.txt");
    oldFile.renameTo(newFile);
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    disposal();
    }}
      

  2.   

    刚刚这个程序有点问题,它相当于剪切的功能,会将原文件删除!!!
    ------------------/**
     * project_name: Test
     * package_name: csdn_Test_20071126
     * package_declaration: package csdn_Test_20071126;
     * filename: RemoveFileTest.java
     * author: yuhaiming
     * date: 2007-12-4
     */
    package csdn_Test_20071126;
    import java.io.*;
    public class RemoveFileTest {
    /**
     * 主函数处理
     */
    public static void disposal(){
    try{
    File oldFile = new File("test.txt");
    File newFile = new File("testResult.txt");
    BufferedReader reader = new BufferedReader(new FileReader(oldFile));
    BufferedWriter writer = new BufferedWriter(new FileWriter(newFile));
    String read_line = reader.readLine();
    StringBuffer buffer = new StringBuffer(read_line);
    System.out.println(read_line);
    while(read_line!=null){
    buffer.append(read_line+"\n");
    read_line = reader.readLine();
    }
    writer.write(buffer.toString());
    reader.close();
    writer.close();
    }catch(Exception e){
    e.printStackTrace();
    }

    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    disposal();
    }}
      

  3.   

    大海力量,你的程序执行后,结果不会换行的,
    我在text.txt里面有三行内容,执行完程序后
    testResult.txt里面内容变成了一行.
      

  4.   


    import java.io.*;
    import java.util.Random;class Points  //生成坐标类,这里生成的是1024*768显示器上的坐标
    {
    private int x,y;
    private String tempoint,tempx,tempy;
    private  Random rpoint=new Random();

    public Points()
    {
    this.x=rpoint.nextInt(1025);
    this.y=rpoint.nextInt(769);
    tempx=String.valueOf(x);
    tempy=String.valueOf(y); 
    this.tempoint="("+tempx+","+tempy+")";
    }

    public String getPoint()
    {
    return tempoint;
    }
    }public class t  //主类
    {
    public static void main(String[] args)
     {
        
        
        try{
         Points[] po={
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points(),
         new Points()
         };
        File file=new File("d:\\test_10.dat");
       
        FileWriter fw=new FileWriter(file);
        
        for(int i=1;i<=10;i++)
        {
        
        fw.write("第"+String.valueOf(i)+"点坐标是:"+po[i-1].getPoint()+"\r\n");
        
        }
        fw.close();
        }catch(java.io.IOException e){System.out.println (e);}
     }
    }
      

  5.   

    将我程序里的
    buffer.append(read_line+"\n");
    中的“\n”修改为:
    buffer.append(read_line+System.getProperty("line.separator"));这样就实现了不同平台的换行了
      

  6.   

    public static void main (String [] args) {
            try {
                Random ram = new Random();
                int x = 0;
                int y = 0;
                FileOutputStream fos = new FileOutputStream("c:\\test_10.dat");
                DataOutputStream dos = new DataOutputStream(fos);
                for (int i = 0; i < 10; i++) {
                    x = ram.nextInt();
                    y = ram.nextInt();
                    Point pos = new Point(x, y);
                    String posX = Integer.toBinaryString(pos.x);
                    String posY = Integer.toBinaryString(pos.y);
                    dos.writeBytes("(" + posX + "," + posY + ")\n");
                }
                dos.flush();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }        
        }