import java.io.*;
public class Java_3
{
public static void main(String[] args)
{
Java_3 exceptionExample = new Java_3();
//*********Found**********
try
{
FileInputStream fi = new FileInputStream("C:" + "\\" + "abc.txt");
}
//*********Found**********
catch(FileNotFoundException ex)
{
//*********Found**********
System.out.println(ex.getMessage()+
"请确认文件路径及文件名是否正确!");
}
}
}
import java.io.*;
import java.util.Vector;
public class Java_2{
public static void main(String s[]){
Vector v=new Vector();
try{
//*********Found**********
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //键盘输入
String str = "";
System.out.println("请输入用户和密码信息,中间用空格隔开,输入quit退出:");
while (!(str.equals("quit")||str.equals("QUIT"))){
str = in.readLine();
//*********Found**********
if(isValid(str)) //验证输入是否有空格
v.add(str);
else{
if(!(str.equals("quit")||str.equals("QUIT")))
System.out.println("The string is NOT valid!");
}
}
System.out.println("请输入保存到的文件名:");
//*********Found**********
str=in.readLine();
String curDir = System.getProperty("user.dir");
File savedfile=new File(curDir+"\\"+str);
//*********Found**********
BufferedWriter out = new BufferedWriter(new FileWriter(savedfile));
for(int i=0; i<v.size(); i++){
String tmp=(String)v.elementAt(i);
out.write(tmp);
//*********Found**********
out.write("\n"); //换行
}
out.close();
}
//*********Found**********
catch(Exception e){
System.out.print("ERROR:"+e.getMessage());
}
}
/**
* 判定输入的字符串是否符合规范
* @param s 输入的待校验的字符串
* @return 校验的结果,正确则返回为真
*/
public static boolean isValid(String s){
if(s.indexOf(" ")>0) return true;
else return false;
}
}
import java.io.*;
import java.lang.Thread;
class MyThread extends Thread{
public int x = 0;
//*********Found********
public void run(){
System.out.println(++x);
}
}
//*********Found********
class RThread implements Runnable{
private int x = 0;
public void run(){
System.out.println(++x);
}
}
public class Java_3 {
public static void main(String[] args) throws Exception{
for(int i=0;i<5;i++){
Thread t = new MyThread();
//*********Found********
t.start();
}
Thread.sleep(1000);
System.out.println();
//*********Found********
RThread r = new RThread();
//*********Found********
for(int i=0;i<5;i++){
Thread t = new Thread(r);
t.start();
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Java_3
{
public static void main(String[] args)
{
ExceptTestFrame frame = new ExceptTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ExceptTestFrame extends JFrame
{
public ExceptTestFrame()
{
setTitle("ExceptTest");
Container contentPane = getContentPane();
ExceptTestPanel panel = new ExceptTestPanel();
//*********Found********
contentPane.add(panel);
pack();
}
}
class ExceptTestPanel extends Box
{
public ExceptTestPanel()
{
super(BoxLayout.Y_AXIS);
group = new ButtonGroup();
addRadioButton("整数被零除", new
ActionListener()
{
//*********Found********
public void actionPerformed(ActionEvent event)
{
a[1] = 1 / (a.length - a.length);
}
});
textField = new JTextField(30);
add(textField);
}
//*********Found********
private void addRadioButton(String s, ActionListener listener)
{
JRadioButton button = new JRadioButton(s, false)
{
protected void fireActionPerformed(ActionEvent event)
{
try
{
textField.setText("No exception");
super.fireActionPerformed(event);
}
catch (Exception exception)
{
//*********Found********
textField.setText(exception.toString());
}
}
};
button.addActionListener(listener);
add(button);
group.add(button);
}
private ButtonGroup group;
private JTextField textField;
private double[] a = new double[10];
}
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Java_2
{
public static void main(String args[])
{
if(args.length<2)
{
System.out.println("ERROR: need parameters.");
System.out.println("\n -usage: java <classname> <file1> <file2>");
System.exit(0);
}
File f1=new File(args[0]);
//*********Found**********
File f2=new File(args[1]);
try
{
//*********Found**********
FileReader fr=new FileReader(f2);
FileWriter fw=new FileWriter(f1,true);
int b;
//*********Found**********
while(( b=fr.read() ) != -1 ) fw.write(b);
fr.close();
fw.close();
}
catch(IOException e)
{
e.printStackTrace();
}
System.out.println("has done!");
//*********Found**********
if(f2.delete()) System.out.print("SUCCESS!");
}
}
public class Java_2
{
public static void main(String[] args)
{
Thread t = new SimpleThread("Testing_Thread");
//*********Found**********
t.start() ;
}
}
//*********Found**********
class SimpleThread extends Thread
{
public SimpleThread(String str)
{
//*********Found**********
super(str) ;
}
//*********Found**********
public void run()
{
System.out.println("Running the " + getName() + ":");
for (int i = 0; i < 5; i++)
{
System.out.println("---" + i + "---" + getName());
try
{
sleep((int)(2 * 100));
}
//*********Found**********
catch(InterruptedException e) { }
}
}
}