I'm developing an inventory application that in its freeware version will work with the data entered in a txt file line by line, the data structure will be as follows
Barcode + Description + Location "And after locating I want to add a sum, where every time the same code is read it will add +1 in the text file"
Writing code;
String dados;
// lstrNomeArq = (txtScanResult.getText() + ".txt");
File arquivo = new File(Environment.getExternalStorageDirectory(), "/MatheusArrudaDev/InventarioFree/" + timeStamp + "/geral.txt");
String unidademetalicascan = (String) txtScanResult.getText();
Editable localizacao = identestoque.getText();
Editable descricao = txtdescricao.getText();
dados = unidademetalicascan + localizacao;
try {
if (!arquivo.exists()) {
//cria um arquivo (vazio)
arquivo.createNewFile();
}
//caso seja um diretório, é possível listar seus arquivos e diretórios
File[] arquivos = arquivo.listFiles();
//escreve no arquivo
FileWriter fw = new FileWriter(arquivo, true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(unidademetalicascan + " " + descricao +" "+ localizacao);
bw.newLine();
bw.close();
fw.close();
//faz a leitura do arquivo
FileReader fr = new FileReader(arquivo);
BufferedReader br = new BufferedReader(fr);
//equanto houver mais linhas
while (br.ready()) {
//lê a proxima linha
String linha = br.readLine();
//faz algo com a linha
System.out.println(linha);
}
br.close();
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
For example:
The application has read "123" and the product description is "Cream", I want it to write
123 Cream 1
If he reads 123 again, I want him to edit the above line and write
123 Cream 2.