请解决一下问题(用java编写)
编写一程序,可读取文本文件aaa.txt与bbb.txt,将其内容合并后,存成文件ccc.txt....
编写一程序,可读取文本文件aaa.txt与bbb.txt ,将其内容合并后,存成文件ccc.txt.
展开
2个回答
展开全部
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class G {
private static final ActionListener Open = null;
JFrame f = new JFrame("记事本");
JTextArea z = new JTextArea();
JMenuBar m = new JMenuBar();
JMenu m1 = new JMenu("文件(F)");
JMenu m2 = new JMenu("编辑(E)");
JMenu m3 = new JMenu("格式(O)");
JMenu m4 = new JMenu("查看(V)");
JMenu m5 = new JMenu("帮助(H)");
JMenuItem t1;
JMenuItem t2;
JMenuItem t3;
JMenuItem t4;
JMenuItem t5;
JMenuItem t6;
JMenuItem t7;
JMenuItem i1;
JMenuItem i2;
JMenuItem i3;
JMenuItem i4;
JMenuItem i5;
JMenuItem i6;
JMenuItem i7;
JMenuItem i8;
JMenuItem i9;
JMenuItem i10;
JMenuItem i11;
JMenuItem e1;
JMenuItem e2;
JMenuItem n1;
JMenuItem c;
JMenuItem c1;
public JMenuItem make(String name) {
JMenuItem x = new JMenuItem(name);
return x;
}
public void ii() {
t1 = make("新建");
t2 = make("打开");
t3 = make("保存");
t4 = make("另存为");
t5 = make("页面设置");
t6 = make("打印");
t7 = make("退出");
i1 = make("撤消");
i2 = make("剪切");
i3 = make("复制");
i4 = make("粘贴");
i5 = make("删除");
i6 = make("查找");
i7 = make("查找下一个");
i8 = make("替换");
i9 = make("转到");
i10 = make("全选");
i11 = make("时间/日期");
e1 = make("自动换行");
e2 = make("字体");
n1 = make("状态栏");
c = make("帮助主题");
c1 = make("关于记事本");
t2.addActionListener(new Open());
t4.addActionListener(new Save());
m1.add(t1);
m1.add(t2);
m1.add(t3);
m1.add(t4);
m1.add(t5);
m1.add(t6);
m1.add(t7);
m2.add(i1);
m2.add(i2);
m2.add(i3);
m2.add(i4);
m2.add(i5);
m2.add(i6);
m2.add(i7);
m2.add(i8);
m2.add(i9);
m2.add(i10);
m2.add(i11);
m3.add(e1);
m3.add(e2);
m4.add(n1);
m5.add(c);
m5.add(c1);
}
public void sheding() {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.add(m1);
m.add(m2);
m.add(m3);
m.add(m4);
m.add(m5);
f.setJMenuBar(m);
f.add(z);
f.setSize(500, 500);
f.setVisible(true);
}
class Open implements ActionListener {
public void actionPerformed(ActionEvent e) {
Frame frame = new Frame("打开");
FileDialog dialog = new FileDialog(frame);
dialog.setVisible(true);
String dir = dialog.getDirectory();
String filename = dialog.getFile();
String path = dir + filename;
NoteIface iface = new NoteImpl();
String[] a = iface.open(path);
for (int i = 0; i < a.length; i++) {
if (a != null) {
z.append(a[i] + "\n");
}
}
}
}
class Save implements ActionListener{
public void actionPerformed(ActionEvent e) {
Frame frame = new Frame("另存为");
FileDialog dialog = new FileDialog(frame);
dialog.setVisible(true);
String dir = dialog.getDirectory();
String filename = dialog.getFile();
String path = dir + filename;
NoteIface iface =new NoteImpl();
String str = z.getText();
iface.Save(str, path);
}
}
public static void main(String[] args) {
G g = new G();
g.ii();
g.sheding();
}
}
研究去吧
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class G {
private static final ActionListener Open = null;
JFrame f = new JFrame("记事本");
JTextArea z = new JTextArea();
JMenuBar m = new JMenuBar();
JMenu m1 = new JMenu("文件(F)");
JMenu m2 = new JMenu("编辑(E)");
JMenu m3 = new JMenu("格式(O)");
JMenu m4 = new JMenu("查看(V)");
JMenu m5 = new JMenu("帮助(H)");
JMenuItem t1;
JMenuItem t2;
JMenuItem t3;
JMenuItem t4;
JMenuItem t5;
JMenuItem t6;
JMenuItem t7;
JMenuItem i1;
JMenuItem i2;
JMenuItem i3;
JMenuItem i4;
JMenuItem i5;
JMenuItem i6;
JMenuItem i7;
JMenuItem i8;
JMenuItem i9;
JMenuItem i10;
JMenuItem i11;
JMenuItem e1;
JMenuItem e2;
JMenuItem n1;
JMenuItem c;
JMenuItem c1;
public JMenuItem make(String name) {
JMenuItem x = new JMenuItem(name);
return x;
}
public void ii() {
t1 = make("新建");
t2 = make("打开");
t3 = make("保存");
t4 = make("另存为");
t5 = make("页面设置");
t6 = make("打印");
t7 = make("退出");
i1 = make("撤消");
i2 = make("剪切");
i3 = make("复制");
i4 = make("粘贴");
i5 = make("删除");
i6 = make("查找");
i7 = make("查找下一个");
i8 = make("替换");
i9 = make("转到");
i10 = make("全选");
i11 = make("时间/日期");
e1 = make("自动换行");
e2 = make("字体");
n1 = make("状态栏");
c = make("帮助主题");
c1 = make("关于记事本");
t2.addActionListener(new Open());
t4.addActionListener(new Save());
m1.add(t1);
m1.add(t2);
m1.add(t3);
m1.add(t4);
m1.add(t5);
m1.add(t6);
m1.add(t7);
m2.add(i1);
m2.add(i2);
m2.add(i3);
m2.add(i4);
m2.add(i5);
m2.add(i6);
m2.add(i7);
m2.add(i8);
m2.add(i9);
m2.add(i10);
m2.add(i11);
m3.add(e1);
m3.add(e2);
m4.add(n1);
m5.add(c);
m5.add(c1);
}
public void sheding() {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.add(m1);
m.add(m2);
m.add(m3);
m.add(m4);
m.add(m5);
f.setJMenuBar(m);
f.add(z);
f.setSize(500, 500);
f.setVisible(true);
}
class Open implements ActionListener {
public void actionPerformed(ActionEvent e) {
Frame frame = new Frame("打开");
FileDialog dialog = new FileDialog(frame);
dialog.setVisible(true);
String dir = dialog.getDirectory();
String filename = dialog.getFile();
String path = dir + filename;
NoteIface iface = new NoteImpl();
String[] a = iface.open(path);
for (int i = 0; i < a.length; i++) {
if (a != null) {
z.append(a[i] + "\n");
}
}
}
}
class Save implements ActionListener{
public void actionPerformed(ActionEvent e) {
Frame frame = new Frame("另存为");
FileDialog dialog = new FileDialog(frame);
dialog.setVisible(true);
String dir = dialog.getDirectory();
String filename = dialog.getFile();
String path = dir + filename;
NoteIface iface =new NoteImpl();
String str = z.getText();
iface.Save(str, path);
}
}
public static void main(String[] args) {
G g = new G();
g.ii();
g.sheding();
}
}
研究去吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception{
BufferedReader br1 = new BufferedReader(new FileReader("D:\\aaa.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("D:\\bbb.txt"));
FileWriter pw=new FileWriter("D:\\ccc.txt",true);
BufferedWriter bw = new BufferedWriter(pw);
String lineContent = null ;
while( (lineContent = br1.readLine()) != null){
bw.write(lineContent);
bw.newLine();
}
while( (lineContent = br2.readLine()) != null){
bw.write(lineContent);
bw.newLine();
}
bw.close();
br1.close();
br2.close();
pw.close();
}
}
-----------------------------------------------
能完成你说的`
public class Test {
public static void main(String[] args) throws Exception{
BufferedReader br1 = new BufferedReader(new FileReader("D:\\aaa.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("D:\\bbb.txt"));
FileWriter pw=new FileWriter("D:\\ccc.txt",true);
BufferedWriter bw = new BufferedWriter(pw);
String lineContent = null ;
while( (lineContent = br1.readLine()) != null){
bw.write(lineContent);
bw.newLine();
}
while( (lineContent = br2.readLine()) != null){
bw.write(lineContent);
bw.newLine();
}
bw.close();
br1.close();
br2.close();
pw.close();
}
}
-----------------------------------------------
能完成你说的`
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询