2013-12-11 112 views
-1

此代碼找不到緩衝讀取器應從中讀取的文件,並且我在eclipse項目中的src文件夾中有文件,但它仍不會從文件中讀取任何人都知道問題是什麼。FileNotFound異常,雖然文件已存在

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.math.*; 
import java.util.ArrayList; 


public class Encrypt { 
public static ArrayList<String> data = new ArrayList<String>(); 
public static BigInteger [] keys = new BigInteger[3]; 
    public static BigInteger n; 
public static double e; 
public static BigInteger d; 
public static String line; 
public static String result; 
    public static String [] temp; 
public static BigInteger tempVar; 
public static BigInteger tempResult; 
public static int tempVar2; 
public static void encryption(ArrayList<String> data) throws IOException{ 
    for (int i = 0; i<data.size(); i++){ 
    if(data.get(i)!= null){ 

     temp = new String[data.get(i).split(" ").length]; 
     temp = data.get(i).split(" "); 
     for(int j = 0; j<temp.length;j++){ 
      for (int k = 0; k< temp[j].length(); k++){ 
       tempVar2 = (int)temp[j].charAt(k); 
         tempVar=BigInteger.valueOf((long)Math.pow(tempVar2,e)); 
        tempResult = (tempVar.remainder(n)); 
       result =""+ tempResult; 
       LogEncrypt(result); 
      } 

     } 
    } 
} 

} 
public static void read() throws IOException{ 
try { 
    BufferedReader br = new BufferedReader(new FileReader("plainText.txt")); 
    System.out.println(br.ready()); 
    while ((line = br.readLine()) != null) { 
     data.add(br.readLine()); 
    } 
    System.out.println("done with text"); 
} catch (FileNotFoundException e) { 
    System.out.println("please add the text file"); 
    e.printStackTrace(); 
} 
try { 
     BufferedReader ba = new BufferedReader(new FileReader("Key.txt")); 
     System.out.println(ba.ready()); 
     int i =0; 
     while ((line = ba.readLine()) != null) { 
     keys[i] = new BigInteger(ba.readLine()); 
     i++; 
     } 
     n = keys[0]; 
     e = keys[1].doubleValue(); 
     d = keys[2]; 
     System.out.println("done with key"); 

    } catch (FileNotFoundException e) { 
     System.out.println("please add the key file"); 
     e.printStackTrace(); 
    } 

} 
public static void LogEncrypt(String result) throws IOException { 
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt")); 
try { 

     out.write(result); 
     out.newLine(); 
} catch(IOException e1) { 
    System.out.println("Error during reading/writing"); 
} finally { 
    out.close(); 
} 


} 
public static void main(String[]args) throws IOException{ 
read(); 
encryption(data); 
} 
} 

+0

最有可能你找錯了地方。打印你嘗試訪問該文件的* full *目錄路徑,並確保它是正確的。 –

回答

1

把文件中的SRC之外,或者至少是「SRC /」添加到該文件的位置

+0

或加載文件作爲資源 – MadProgrammer

+0

非常感謝它的人工作 – user2287768

+0

@ user2287768沒有問題有自己的困難很大。 – JustBrenkman

相關問題