【java作业】2、 编写两个函数,分别使用字节流、字符流实现文件的拷贝;点击按钮,将第三个文本框的字符串的值设置为第一个文本框的字符串+第二个文本框的字符串。

拷贝文件 :

public static void  copy1(String a,String b) throws IOException {
    FileInputStream input = new FileInputStream(a);
    File file = new File(a);
    if(!file.canRead()||file.length() == 0) return ;
    FileOutputStream output = new FileOutputStream(b);


    int n = -1;
    while((n = input.read() )!= -1)
    {
        String s  = new String(hasRead,0,n);
       output.write(n);
    }
  input.close();
    output.close();

}

public static void  copy2(String a,String b) throws IOException {
    FileReader input = new FileReader(a);
    File file = new File(a);
    if(!file.canRead()||file.length() == 0) return ;
    FileWriter output = new FileWriter(b);
    char c[]=new char[1000];

    int n = -1;
    while((n = input.read(c) )!= -1)
    {

        output.write(c);
    }
    input.close();
    output.close();

}



字符串拼接:

   public static void main(String[]args){
        //InputArea newarea = new InputArea("name");
        Frame f=new Frame("字符串拼接");

        //设置分本框
        TextField tf1=new TextField(8);
        TextField tf2=new TextField(8);
        JButton b=new JButton("连接");
        TextField tf3=new TextField(15);
        //设置文本域
        //TextArea ta=new TextArea(10,40);

        f.setBounds(200, 200, 400, 300);



        //设置按钮功能
        b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //获取文本框的内容,并去除字符串前面和后面的空格
                String s=tf1.getText();
                String s2 = tf2.getText();

          

            }
        });

  


    }

为了防止作业雷同只写了一部分代码上去,如果需要全部的代码私我就好。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值