1
我正在寫一個簡單的程序,使用Vigenere密碼對文本文件中的文本進行加密和解密。該大綱代碼粘貼下面java流關閉錯誤
import java.io.*;
public class VigenereCipher
{
public static void main(String [] args)
throws IOException
{
char [][] cipherKey = new char[26][26];
String fileName, keyword;
System.out.println("Enter the file Name to Read");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
fileName = br.readLine();
System.out.println("Enter the Keyword");
keyword = br.readLine();
keyword = keyword.toUpperCase();
br.close();
//to read the file line by line and convert
br = new BufferedReader(new FileReader(fileName));
while((line = br.readLine()) != null){
line = line.toUpperCase();
//More code to perform the substitution, removed to reduce the code
}
br.close();
//code for decryption
System.out.println("Enter the filename to decode");
try
{
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
fileName = br1.readLine();
br1.close();
}catch(Exception ex){ System.out.println(ex.getMessage());}
System.out.println(fileName);
br = new BufferedReader(new FileReader(fileName));
while((line = br.readLine()) != null){
line = line.toUpperCase();
//The decryption code is here
}
br.close();
}
}
我從try catch塊
Stream closed
我不明白,在System.in流可以如何被關閉下面的消息? 我犯了什麼錯誤,我該如何解決?
謝謝,我會那樣做的。 但是有沒有什麼方法可以使用相同的緩衝讀取器? 這只是出於好奇。 – nikhil 2012-02-19 13:50:30