2015-10-05 83 views
-2

我正在開發一個web項目,它將用於登錄頁面。我有一個名爲database.txt的文件,其中存儲了用戶的信息(名稱,電子郵件,密碼)。我還沒有登錄頁面,但是我已經創建了一個方法並試圖對其進行測試,但是我沒有得到任何結果作爲輸出來查看它是否有效。在文本文件中查找電子郵件地址

這裏是我當前的代碼:

public static User select(String emailAddress)  
{ 
    emailAddress = "[email protected]";//testing with an email that is in the database.txt file. 
    User userID = null; 
    String file="/Users/test/Downloads/MyTwitter/web/database.txt"; 
    Scanner scanner = new Scanner(file); 
    while (scanner.hasNextLine()) { 
     final String lineFromFile = scanner.nextLine(); 
     if (lineFromFile.contains(emailAddress)) { 
      System.out.println("I found" + emailAddress); 
      userID = new User(); 
      break;    
     } 

    } 
    return userID;  
} 
+1

您有具體問題嗎? –

+0

我的意思不是貶低,但是這個網站是否適合專業人士? –

+0

進入本網站沒有任何障礙......所以任何人都可以註冊併發布問題。 –

回答

0

你調用了錯誤的掃描儀的構造函數,你考取的字符串值。試試這個:

Scanner scanner = new Scanner(new File("/Users/test/Downloads/MyTwitter/web/database.txt")); 
相關問題