I. Anomalies
Java's handling of the exception is the same as Delphi, not deliberately to avoid it, but wait for it to occur after the recovery.
Delphi exception Handling is simply a statement
Try
Except//异常发生后就转入此处执行
Finally//不管异常发不发生,都转入此处运行
End
Similarly, the basic form of Java exception handling is as follows
try{
}catch(ExceptionType1 e){
file&://对/异常情况1的处理
}catch(ExceptionType2 e){
file&://对/异常情况2的处理
throw(e)//抛出异常,和Delphi中的raise是一回事
}
To add, for most exceptions, if you want to explicitly throw in a normal running program rather than in a program that catches exceptions, the Java compiler requires you to make a declaration of the exception you are about to throw, otherwise it is not allowed to compile. This task is done by throws.
Two. Java input and output stream
2.1 Output
System.out.print file&://这/里out是一个静态方法哦
System.out.println
System.err.print file&://err/和out一样也是标准输出,至于有什么不同,我目前还不清楚
System.err.println
2.2 Input
System.in.read()
2.3 Operation of files
Just a few examples with annotations are all you need.
The first is a program that displays basic information about a file
import java.io.*;//into the IO-related class
class fileinfo{
file&://note/meaning, the main function must be static method
public static void Main (String args[]) throws ioexception{
file filetocheck;//Use a file object to create an instance
if (args.length>0) {
for (int i=0;i<args.length;i++) {
Filetocheck=new file (args[i]);//Allocate space for the file object
Info (filetocheck);//This reference must be static. State method member
}
}
else{
System.out.println ("no file Given");
}
public static void info (File f) throws ioexception{
System.out.println ("Name:" +f.getname ());
System.out.println ("Path:" +f.getpath ());
if (f.exists ()) {
System.out.println ("File exists.");
System.out.print (F.canread ()? "and is readable": "))//Judgment function, if the condition is satisfied, output the former, or output the latter
System.out.print (F.CANWR ITE ()? " and is writable ":"));
System.out.print (".");
System.out.println ("File is" +f.length () + "bytes.");
}
else{
System.out.println ("File does not exist.");
}
}