0

If I have 2 text files like this

textfile1:

textflie1 have
123456789 apple back 400000 1234
987654321 egg blue 500000 4321

textfile2:

 5678900 fish dog 400000 4567
 1234567 cat hat 500000 8905

And I read them like this:

public class main extends javax.swing.JFrame { 
ArrayList<String>name = new ArrayList();
ArrayList<String>acNum  = new ArrayList();
ArrayList<String>surname = new ArrayList();
ArrayList<String>pass = new ArrayList();
ArrayList<String>hasMoney = new ArrayList(); 
//ต่างธนาคาร
ArrayList<String>name2 = new ArrayList();
ArrayList<String>acNum2  = new ArrayList();
ArrayList<String>surname2 = new ArrayList();
ArrayList<String>pass2 = new ArrayList();
ArrayList<String>hasMoney2 = new ArrayList(); public main(){
    initComponents();
try{    
     File f = new File("file1.txt");
    Scanner a = new Scanner(f);
    while( a.hasNextLine()){
    String u[] = a.nextLine().split(" ");
    name.add(u[1]);
    surname.add(u[2]);
    acNum.add(u[0]);
    pass.add(u[4]);
    hasMoney.add(u[3]);
    }
}catch (FileNotFoundException e){
 JOptionPane.showMessageDialog(null, 
           "Error opening accounts file.");
}
//ต่างธนาคาร
try{    
    File f = new File("file2.txt");
    Scanner a = new Scanner(f);
    while( a.hasNextLine()){
    String u[] = a.nextLine().split(" ");
    name2.add(u[1]);
    surname2.add(u[2]);
    acNum2.add(u[0]);
    pass2.add(u[4]);
    hasMoney2.add(u[3]);
}
}catch (FileNotFoundException e){
 JOptionPane.showMessageDialog(null, 
           "Error opening accounts file.");
}
}

and I do this:

String me = acInField.getText();
if(acNum.contains(me)){    
            namu = name.get(acNum.indexOf(me));
            mymon = hasMoney.get(acNum.indexOf(me));
            surr=  surname.get(acNum.indexOf(me));
            String namsur= namu+" "+surr;
            new 
inputMoney(namsur,Integer.parseInt(mymon),0).setVisible(true);
            this.dispose();  
}else if(acNum2.contains(me)){     

            namu = name2.get(acNum2.indexOf(me));
            mymon = hasMoney2.get(acNum2.indexOf(me));
            surr=  surname2.get(acNum2.indexOf(me));
            String namsur= namu+" "+surr;
            new 
inputMoney(namsur,Integer.parseInt(mymon),0).setVisible(true);
            this.dispose();  } else{
}

and this is inputMoney:

enter code here
public String namsur ;
public int mymoney ;
public int myvat=0;
public int bankin = 0 ;

public inputMoney() {
    initComponents();

}
public inputMoney(String name ,int money,int vat){
    initComponents();
    namsur = name;
    myvat += vat;
    mymoney = money+vat; 
    inMo2.setText(namsur);
}

And I want to save mymoney back on textfile that I got them (in the same place and not change other value in old textfile)

illright
  • 3,991
  • 2
  • 29
  • 54
  • 2
    Possible duplicate of [Inserting text into an existing file via Java](http://stackoverflow.com/questions/289965/inserting-text-into-an-existing-file-via-java) – Robert Apr 30 '17 at 05:23
  • Welcome to Stack Overflow! Your post contains a lot of code - that makes your question difficult to comprehend. Please, refer to this help section on [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – illright May 02 '17 at 07:05
  • Does your code compile at all? what is public main(){... ? – Stimpson Cat May 02 '17 at 07:10

0 Answers0