How to modify the lines of a txt file in java?

0

I have a dilemma that I can not solve. It turns out that I have a text file that stores user information, each line of the file corresponds to a user and its attributes are separated by #.

  

id # pass # td # balance

So that's how the file would stay (obviously it's not 3 users, it's 50 users, that's 50 lines):

  

01 # hello111 # cc # 100.0

     

02 # hello122 # ps # 110.0

     

03 # hello133 # di # 120.0

How do I modify an attribute of line x within the file;

Example: I want to change the balance of user 02 in the file.

Note: the lines are not the same, the size of the line varies according to its attributes (the only attribute that maintains the size is the id that is a unique string of 5 letters).

How do I do it? Thanks.

    
asked by mb0 12.05.2017 в 19:44
source

1 answer

1

I recommend you investigate all about the Streams / files I did not understand the question well, but to be able to insert characters to a txt with java you can use the class Filewriter which is the one that is responsible for inserting characters, I'll give you an example:

File archivo = new File("ejemplo.txt"); // este es el archivo que insertaras caracteres
FileWriter escribir = new FileWriter(archivo);
String texto = "aqui van los caracteres a insertar";
for(int i=0; i<texto.length();i++){
escribir.write(texto.charAt(i));
escribir.close();

I hope and be the one you are looking for. Remember is to add characters to a text file greetings!

    
answered by 12.05.2017 / 20:34
source