【java作业】2、 编写两个函数,分别使用字节流、字符流实现文件的拷贝;点击按钮,将第三个文本框的字符串的值设置为第一个文本框的字符串+第二个文本框的字符串。
生活随笔
收集整理的這篇文章主要介紹了
【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();}});}為了防止作業雷同只寫了一部分代碼上去,如果需要全部的代碼私我就好。
總結
以上是生活随笔為你收集整理的【java作业】2、 编写两个函数,分别使用字节流、字符流实现文件的拷贝;点击按钮,将第三个文本框的字符串的值设置为第一个文本框的字符串+第二个文本框的字符串。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UnhandledPromiseReje
- 下一篇: 【学习笔记】JAVA IO与NIO(ne