⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myexception.java

📁 用java实现简单的:简单聊天程序 多线程 计数器 记事本 马鞍点 扇子 学生成绩管理系统 异常处理 字符串类
💻 JAVA
字号:
import java.io.*; 

public class Myexception{
     public static void main(String[] args){
     	    int a=0,b=0,chi;
     	    int[] beyondarray=new int[4];
     	    char ch;
     	    File MyPath=new File("D:\\java");   //指定路径
     	    if(!MyPath.exists())  //若此目录不存在,则创建之
     	         MyPath.mkdir();
     	    File MyFile1=new File(MyPath,"inout.html");  //创建指定目录下指定文件的文件类对象
   
     	    try{
     	    	   b=25/a;   //除数0
     	    	   Thread.sleep(2000); //延迟
     	    }catch(ArithmeticException e){  //处理除数0异常
     	         System.out.println("0除某数错误:"+e.getMessage());
     	         System.out.println("a的值为:"+a);
     	    }catch(InterruptedException e){  //处理延迟异常
     	         System.out.println("延迟失败"+e.toString());
     	    }
     	    try{
     	         b=beyondarray[9];   //数组下标越界	
     	    }
     	    catch(ArrayIndexOutOfBoundsException e){
     	         System.out.println("数组下标越界"+e.getMessage());	
     	    }
     	    try{
     	    	   FileOutputStream fout=new FileOutputStream(MyFile1);
     	    	   System.out.println("Input a String finished with # please:");
     	    	   while((ch=(char)System.in.read())!='#')  //写数据  	    	
     	    	        fout.write(ch);
     	    	   fout.close();
     	    	   System.out.println("");   //换行
     	    }
     	    catch(FileNotFoundException e){  //文件不能找到异常
     	    	   System.err.println(e);    	    	
     	    }
     	    catch(IOException e){
     	    	   System.err.println(e);
     	    }
     	    try{  //先得到一个绝对文件路径和文件名
     	    	   FileInputStream fin=new FileInputStream(MyFile1);
     	    	   while((chi=fin.read())!=-1)    //读数据
     	    	        System.out.print((char)chi);
     	    	   fin.close();     	    	
     	    }
     	    catch(IOException ioe){   //输入输出异常的错误,文件不能打开异常
     	         System.out.println("文件不能打开");
     	         System.err.println(ioe.toString());
     	    }   	
     	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -