Mycp补交作业

Mycp补交作业

代码

import java.io.;
import java.lang.;
import java.util.Scanner;
public class MyCP {
public static void main(String args[]) {
try {
        FileReader file=new FileReader("/Users/windows/Desktop/mycp.txt");
        OutputStreamWriter binary=new OutputStreamWriter(new FileOutputStream("/Users/windows/Desktop/mycp.txt"));
        BufferedReader br=new BufferedReader(file);
        String strs=null;

        while ((strs=br.readLine())!=null) {

            System.out.println(strs);
            int num=Integer.parseInt(strs);
            //for (int i=0;i<strs.length();i++){

                binary.write(Integer.toBinaryString(num));
                System.out.print(Integer.toBinaryString(num));
            //}


        }
        binary.close();
    } catch (FileNotFoundException e) {
        System.out.println(" NO file exist");
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println();
    try {

        FileReader file2=new FileReader("C:\Users\lenovo\zhuanyedajiesanshinian20155307\zhuanyedajiesanshinian20155307");
        OutputStreamWriter test=new OutputStreamWriter(new FileOutputStream("C:\\Users\\LJY\\IdeaProjects\\Stream\\src\\test2.txt"));
        BufferedReader br2=new BufferedReader(file2);
        String strs2=null;

        while ((strs2=br2.readLine())!=null) {

            System.out.println(strs2);
            //int num2=Integer.parseInt(strs2);
            //for (int i=0;i<strs.length();i++){

            test.write(Integer.parseInt(strs2,2));
            System.out.println(Integer.parseInt(strs2,2));
            //}


        }
        test.close();
    } catch (FileNotFoundException e) {
        System.out.println("file doesn't exist");
    } catch (IOException e) {
        e.printStackTrace();
    }


}
}

运行截图

posted on 2017-06-04 12:00  方片8  阅读(141)  评论(0编辑  收藏  举报