DataInOut 文件输入输出示例

public class DataInOutTest {
    public static void main(String[] args) {
        DataOutputStream dos=null;
        DataInputStream dis=null;
        FileInputStream fis=null;
        FileOutputStream fos=null;

        try{
            fis = new FileInputStream("D:\\doc\\User.class");
            dis = new DataInputStream(fis);

            fos =new FileOutputStream("D:\\doc\\newUser.class");
            dos =new DataOutputStream(fos);

            int temp;
            while (((temp=dis.read())!=-1)){
                fos.write(temp);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try{
                if (dis!=null)
                    dis.close();;
                    if (fis!=null)
                        fis.close();
                    if (fos!=null)
                        fos.close();
                    if (dos!=null)
                        dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

 

posted @ 2024-10-05 18:23  麦克斯-侯  阅读(3)  评论(0编辑  收藏  举报
百纵科技