file io - Replacing a line of text in Java -


I have an ATM and I need to open a text file in which the account information is in the following format: < Ul

  • Account Name
  • Last Name
  • First Name
  • Balance (None will be empty but this site does not let me)

    The file name is Accountnfomation.txt.

    Actually, I have to change / change the balance value based on the user's wish. I know how to know the account number in the text file, but I do not know how to leave the next two lines and edit it. Here are some code I have written:

      try {scanner account = new scanner (new file ("Account Information.")); FileOutputStream Account2 = New FileOutputStream ("AccountInformation.txt", true); While (account. HasNextLine ()) {String NextToken = Account. If (nextToken.equalsIgnoreCase (MyLoginID)) {// search for a specific match // will be here to edit the rest of the balance}}}   

    It has yet to me It finds the account number, but I do not know what to do next.

    In your problem, it would be best to get a line that you want to change, change it , And leave everything else the same. Unfortunately there is not a collection of file lines, it is a collection of bytes. If you want to change "1000" from "10" then you need to insert some new bytes, that means everything behind it needs to go down some bytes (potentially four or lots, assuming utf8) .

    In the real world, we do not store data in flat files, assuming that you still really want a simple, file-based, human-readable format:

    • Use a file per entry. You have a directory with lots of files, but rewriting changed files and sequencing with file names will be hard work by the OS.
    • Use a fixed field width format Define the width of each field and go to the data you want You can access your data like a large array.
    • Use a predefined format with easy-to-use tools for parsing and manipulation. XML and CSVs come to mind

  • Comments

    Popular posts from this blog

    Verilog Error: output or inout port "Q" must be connected to a structural net expression -

    jasper reports - How to center align barcode using jasperreports and barcode4j -

    c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -