Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java bufferedreader读取_Java_Bufferedreader_Accountmanager - Fatal编程技术网

Java bufferedreader读取

Java bufferedreader读取,java,bufferedreader,accountmanager,Java,Bufferedreader,Accountmanager,我正在尝试建立一个不同类型的登录系统。我想让它读取一个.txt文件,其中包含如下详细信息 (格式为用户名-密码-布尔值): 然而,这是它变得非常困难的地方。然后我想检查布尔值,如果它是“true”,跳过帐户,如果不是,使用它。从那里,当帐户“完成”时,将其设置为“true” 我希望其用法如下: username = nextAvaialableAccount.getUsername(); password = nextAvailableAccount.getPassword(); 我对如何实现

我正在尝试建立一个不同类型的登录系统。我想让它读取一个.txt文件,其中包含如下详细信息 (格式为用户名-密码-布尔值):

然而,这是它变得非常困难的地方。然后我想检查布尔值,如果它是“true”,跳过帐户,如果不是,使用它。从那里,当帐户“完成”时,将其设置为“true”

我希望其用法如下:

username = nextAvaialableAccount.getUsername();
password = nextAvailableAccount.getPassword();
我对如何实现这一点有一个非常基本的概念,但总的来说,我对如何实现布尔部分感到困惑。我不太关心性能,我只是希望系统能够完美地工作,这样我就可以不断地删除帐户并将其添加到.txt中。我对其他基本文件,如.xml(guest51等)持开放态度,我只是对如何真正“设计”系统来实现它感到非常困惑

编辑:我想这样做,所以我更改了我使用的任何帐户的.txt中的布尔值。 最坏的情况是,我必须用Java来做(我仍然不知道如何做)

再次编辑:或者我是否可以在文件夹中使用类似这样的方法进行编辑: /用户/帐户/测试51/


在该目录中,我将创建details.txt,其中包含用户名、密码和布尔值。我想要创建的系统将用于20个帐户,没有什么大的

这将从文本文件中读取示例数据,将用户名和密码放入两个字符串中,将布尔值放入一个
布尔值中。它除了将这些信息打印到屏幕上(根本没有写入文件——这是一个只读的示例)之外什么都不做,但它应该能够帮助您完成任务

   import  java.io.File;
   import  java.io.IOException;
   import  org.apache.commons.io.FileUtils;
   import  org.apache.commons.io.LineIterator;
   import  org.apache.commons.lang.StringUtils;
/**
   <P>{@code java ReadInActiveAccountsFromFile C:\java_code\username_password_active.txt}</P>
 **/
public class ReadInActiveAccountsFromFile  {
   public static final void main(String[] rqdInputPathInStrArray)  {
      //Read command-line
         String sSrc = null;
         try  {
            sSrc = rqdInputPathInStrArray[0];
         }  catch(IndexOutOfBoundsException ibx)  {
            System.out.println("Missing one-and-only required parameter: The full path to Java source-code file.");
            return;
         }

      //Open input file
         File inputFile = new File(sSrc);
         LineIterator lineItr = null;
         try  {
            lineItr = FileUtils.lineIterator(inputFile);
         }  catch(IOException iox)  {
            System.out.println("Cannot open \"" + sSrc + "\". " + iox);
            return;
         }

      while(lineItr.hasNext())  {
         String line = lineItr.next();
         String[] userPassIsActive = line.split(" ");
         String username = userPassIsActive[0];
         String password = userPassIsActive[1];
         boolean isActive = Boolean.parseBoolean(userPassIsActive[2]);

         System.out.println("username=" + username + ", password=" + password + ", isActive=" + isActive + "");
      }
   }
}

if(inputString.equals(“true”))booleanVariable=true;else booleanVariable=false@PM77-1我想他想替换文本文件的布尔值value@xp500-可能是。不清楚。您可以序列化帐户类并将其保存到文件中。@PM77-1我想替换文本文件的布尔值,是的。对不起,我不清楚。看看主帖子中的编辑,我已经详细介绍了
   import  java.io.File;
   import  java.io.IOException;
   import  org.apache.commons.io.FileUtils;
   import  org.apache.commons.io.LineIterator;
   import  org.apache.commons.lang.StringUtils;
/**
   <P>{@code java ReadInActiveAccountsFromFile C:\java_code\username_password_active.txt}</P>
 **/
public class ReadInActiveAccountsFromFile  {
   public static final void main(String[] rqdInputPathInStrArray)  {
      //Read command-line
         String sSrc = null;
         try  {
            sSrc = rqdInputPathInStrArray[0];
         }  catch(IndexOutOfBoundsException ibx)  {
            System.out.println("Missing one-and-only required parameter: The full path to Java source-code file.");
            return;
         }

      //Open input file
         File inputFile = new File(sSrc);
         LineIterator lineItr = null;
         try  {
            lineItr = FileUtils.lineIterator(inputFile);
         }  catch(IOException iox)  {
            System.out.println("Cannot open \"" + sSrc + "\". " + iox);
            return;
         }

      while(lineItr.hasNext())  {
         String line = lineItr.next();
         String[] userPassIsActive = line.split(" ");
         String username = userPassIsActive[0];
         String password = userPassIsActive[1];
         boolean isActive = Boolean.parseBoolean(userPassIsActive[2]);

         System.out.println("username=" + username + ", password=" + password + ", isActive=" + isActive + "");
      }
   }
}
[C:\java_code\]java ReadInActiveAccountsFromFile C:\java_code\username_password_active.txt
username=guest51, password=password, isActive=true
username=guest52, password=bus, isActive=true
username=guest53, password=password123, isActive=true
username=guest54, password=123password, isActive=false