我的代码不加 throws Exception就要报下面的错.什么道理啊
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class SDec{
public static void main(String args[]) throws Exception
{
FileInputStream f=new FileInputStream("SEnc.dat");
int num=f.available();
byte[] ctext=new byte[num];
f.read(ctext);
FileInputStream f2=new FileInputStream("keykb1.dat");
int num2=f2.available();
byte[] keykb=new byte[num2];
f2.read(keykb);
SecretKeySpec k=new SecretKeySpec(keykb,"DESede");
Cipher cp=Cipher.getInstance("DESede");
cp.init(Cipher.DECRYPT_MODE,k);
byte[] ptext=cp.doFinal(ctext);
String p=new String(ptext,"UTF8");
System.out.println(p);
}
}
--------------------Configuration: <Default>--------------------
C:\SDec.java:8: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream f=new FileInputStream("SEnc.dat");
^
C:\SDec.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown
int num=f.available();
^
C:\SDec.java:11: unreported exception java.io.IOException; must be caught or declared to be thrown
f.read(ctext);
^
C:\SDec.java:12: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream f2=new FileInputStream("keykb1.dat");
^
C:\SDec.java:13: unreported exception java.io.IOException; must be caught or declared to be thrown
int num2=f2.available();
^
C:\SDec.java:15: unreported exception java.io.IOException; must be caught or declared to be thrown
f2.read(keykb);
^
C:\SDec.java:17: unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
Cipher cp=Cipher.getInstance("DESede");
^
C:\SDec.java:18: unreported exception java.security.InvalidKeyException; must be caught or declared to be thrown
cp.init(Cipher.DECRYPT_MODE,k);
^
C:\SDec.java:19: unreported exception javax.crypto.IllegalBlockSizeException; must be caught or declared to be thrown
byte[] ptext=cp.doFinal(ctext);
^
C:\SDec.java:20: unreported exception java.io.UnsupportedEncodingException; must be caught or declared to be thrown
String p=new String(ptext,"UTF8");
^
10 errors
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class SDec{
public static void main(String args[]) throws Exception
{
FileInputStream f=new FileInputStream("SEnc.dat");
int num=f.available();
byte[] ctext=new byte[num];
f.read(ctext);
FileInputStream f2=new FileInputStream("keykb1.dat");
int num2=f2.available();
byte[] keykb=new byte[num2];
f2.read(keykb);
SecretKeySpec k=new SecretKeySpec(keykb,"DESede");
Cipher cp=Cipher.getInstance("DESede");
cp.init(Cipher.DECRYPT_MODE,k);
byte[] ptext=cp.doFinal(ctext);
String p=new String(ptext,"UTF8");
System.out.println(p);
}
}
--------------------Configuration: <Default>--------------------
C:\SDec.java:8: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream f=new FileInputStream("SEnc.dat");
^
C:\SDec.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown
int num=f.available();
^
C:\SDec.java:11: unreported exception java.io.IOException; must be caught or declared to be thrown
f.read(ctext);
^
C:\SDec.java:12: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
FileInputStream f2=new FileInputStream("keykb1.dat");
^
C:\SDec.java:13: unreported exception java.io.IOException; must be caught or declared to be thrown
int num2=f2.available();
^
C:\SDec.java:15: unreported exception java.io.IOException; must be caught or declared to be thrown
f2.read(keykb);
^
C:\SDec.java:17: unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
Cipher cp=Cipher.getInstance("DESede");
^
C:\SDec.java:18: unreported exception java.security.InvalidKeyException; must be caught or declared to be thrown
cp.init(Cipher.DECRYPT_MODE,k);
^
C:\SDec.java:19: unreported exception javax.crypto.IllegalBlockSizeException; must be caught or declared to be thrown
byte[] ptext=cp.doFinal(ctext);
^
C:\SDec.java:20: unreported exception java.io.UnsupportedEncodingException; must be caught or declared to be thrown
String p=new String(ptext,"UTF8");
^
10 errors
解决方案 »
- dom4j解析xml文档时候报错The content of elements must consist of well-formed character da
- myeclipse8.5选中整行 快捷键
- java日期判段 如何判簖是周一
- StringBuffer(int lenth)什么意思
- GUI界面的管理程序·
- 请教如何建立数据库连接池?
- 关于HashMap
- 请问:使用JDBC的PreparedStatement做upadte操作,结果字符串后面出了无数的空格,怎么解决。
- 请问这段Code如何实现在BUTTON CLICK事件中改变BUTTON BACKCOLOR?
- myeclipse出现问题
- 关于JAVA JDK API中各种类的问题?
- 直接使用new 创建一个对象和使用对象引用的区别
1.抛出异常:throws ***Exception,把异常抛出给顶层的调用方法,由它去处理
2.捕捉异常:try-catch-finally,把可能产生异常的代码放在try里面,把要捕捉的异常放在
catch(){...}里面进行处理
一般用try ...catch语句。