0
I’ve been testing several ways to write the data of a variable in a text file (.txt), but I need to know if you can write this variable in a given line, so I could organize multiple data in the same file by manipulating only the desired line.
package geraclube;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.nio.file.Files;
import static java.nio.file.Files.lines;
import static java.nio.file.Files.lines;
import static java.nio.file.Files.lines;
import java.nio.file.Paths;
public class Start {
public static void main(String[] args) throws IOException {
    MoneyGenerator gerM = new MoneyGenerator(); // instancia o gerador de dinheiro
    String saveLoadFile = "dados_java.txt";
    // puxa os dados do arquivo "dados_java.txt", vai puxar os arquivos da Linha 1
    // observem que os itens estão descritos com dois pontos duplos para facilitar...
    //...a identificação dos campos e o split a baixo.
    String moneyLine = Files.readAllLines(Paths.get(saveLoadFile)).get(1);
    String[] parts = moneyLine.split("::");
    //após o split vai separar somente o número real para o código
    int saldoFinal = Integer.parseInt(parts[1]);
    // se o saldo for zero o código vai gerar...
    //...um novo valor através da classe MoneyGenerator.java
    if (saldoFinal == 0) {
        saldoFinal = (gerM.clubMoney);
    }
    System.out.println(saldoFinal);
}
If you fall into "if" I would like to save the result of the variable in the second line of a file. txt without changing the other lines. Is it possible? Or I’d have to use another method?