Java文件读写

// 文件读取

// 方法一

String path = "d:\a.txt";

BufferedReader  b= new BufferedReader(new FileReader(path));

String s;

while ((s = b.readLine()) != null) {

System.out.println(s);





b.close();





//方法二

// String path = "d:\a.txt";

// BufferedInputStream i = new BufferedInputStream(new FileInputStream(path));

// int s1 = 0;

// byte[] b1= new byte[1024];

// while ((s1=i.read(b1)) != -1) {

// System.out.print(new String(b1,0,s1));;

//

// }

// i.close();


管理员 发布于 2021-12-29 17:19

Java教学GUI实例 教程

Frame f = new Frame("test");

Panel p = new Panel();

f.add(p);



Button b1 = new Button("按钮");

p.add(b1);

b1.addActionListener(new ActionListener() {



@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

System.out.println("success");

}



});











f.setSize(300,400);

f.setVisible(true);



}

private class MyActionListener implements ActionListener{





public void actionPerformed(ActionEvent e) {



System.out.println("success");

}



}



管理员 发布于 2021-12-29 16:59