拷贝文件 :
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();
}
});
}
为了防止作业雷同只写了一部分代码上去,如果需要全部的代码私我就好。