2016-08-12 57 views
-1

我希望將控制檯中的所有用戶輸入複製到.txt文件。 這是我的代碼,謝謝!所有從控制檯上的用戶輸入到.txt java

import java.util.Scanner; 
import java.io.Console; 


public class passwordDriver { 

public static void main(String[] args) { 
    Scanner input = new Scanner(System.in); 

    Console cnsl = null; 
    String alpha = null; 

    boolean checkPass = true; 
    // creates a console object 
    cnsl = System.console(); 

    if (cnsl != null) { 
     /** // read line from the user input 
     alpha = cnsl.readLine("Name: "); 

     // prints 
     //System.out.println("Name is: " + alpha); 
    */ 
    } 


    while (checkPass) { 


     try{ 


      // if console is not null 
      if (cnsl != null) { 

       //tell the user what the app does 
       System.out.println("Type your password and check how strong it is!"); 


       // read password into the char array 
       char[] pwd = cnsl.readPassword("Password: "); 



       if (PassCheck.validatePassword(String.valueOf(pwd))) { 
        checkPass = false; 
       } 
       else { 
        System.out.println("Your password is invalid. "); 
       } 
      } 
     }catch(Exception ex){ 

      // if any error occurs 
      ex.printStackTrace(); 
     } 




    } 


} 
+0

而是張貼的絨毛,你也可以使用該解釋發生了什麼問題的空間。 –

+0

OP - 「我想製作一個密碼強度檢查器,它將密碼存儲到一個txt文件中。」這個粗略是強烈的。 – Jeutnarg

回答

0

因此,在你的代碼,你在哪裏檢查密碼只是把這個代碼:

如果輸入的密碼錯誤,則─>

​​
+1

它不起作用喲 – adaminspaceship

+0

當然,它:) :) @adaminspaceship –

+0

它呢! thanksss – adaminspaceship