ok so i want to read a .txt file line by line. I have the code for that BUT i want to keep track of what line im on, i might be completely braindead from working on this whole project forever but heres the line by line code i am using.

// all the code for reading and parsing .txt file and setting up survey (loading)
		File file = new File(txtFile + ".txt");
	    FileInputStream fis = null;
	    BufferedInputStream bis = null;
	    DataInputStream dis = null;

	    try {
	      fis = new FileInputStream(file);

	      // Here BufferedInputStream is added for fast reading.
	      bis = new BufferedInputStream(fis);
	      dis = new DataInputStream(bis);

	      // dis.available() returns 0 if the file does not have more lines.
	      while (dis.available() != 0) {

	      // this statement reads the line from the file and parses them
	      dis.readLine();
	        
	        
	      }

	      // dispose all the resources after using them.
	      fis.close();
	      bis.close();
	      dis.close();

	    } catch (FileNotFoundException e) {
	      e.printStackTrace();
	    } catch (IOException e) {
	      e.printStackTrace();
	    }

is there a way I can keep a line counter because like the way my program is set up, certain lines mean different things to me. I need to use conditions on a lot of the lines, some depending on the number of the line and some depending on what a key word of a line says.

Yes. At the top of whatever method you are in, create an int variable called counter.

int counter = 0;

Then, whenever you go onto a new line, counter++;. If you need to use the counter in more than one method, then declare the variable as a class variable.

> ok so i want to read a .txt file line by line.

Since you are reading textual data, consider using a BufferedReader wrapper up in LineNumberReader to ease your task.

package src.maintenance.Uploader;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyVetoException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

import src.maintenance.Calendar.DateComboBox;
import src.maintenance.DBConn.DBConnect;
import src.maintenance.Functions.Message;
import src.maintenance.Functions.MyField;
import src.maintenance.MainMenu.Sub;
import src.maintenance.core.mainform;

import com.l2fprod.common.swing.JDirectoryChooser;


//import com.sun.deploy.panel.RadioPropertyGroup;
public class fileUploader extends JInternalFrame {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    SimpleDateFormat tformat = new SimpleDateFormat("HH:mm:ss");

    static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat dateformat2 = new SimpleDateFormat("MMddyy");

    static Date today;
    static String output;

    //UBrnchTxtF
    static SimpleDateFormat dateformat1 = new SimpleDateFormat("yyMMdd");
    String myFormatString = "yyMMdd"; 
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date date1 = null;
    Date date2 = null;
    private String date = null;
    static DateComboBox jcboDate = new DateComboBox();

    public static int txnCntr = 1;
    public static int userCntr = 0;
    public static int posCntr = 0;
    static String MySQL = "";

    private JPanel jContentPane = null;

    //label
    private JLabel jlblLocation = null;
    private JLabel jlblOdir = null;
    private JLabel jlblFile = null;
    private JLabel jlblSdate = null;

    //txtfield
    private MyField jtxtDir = null;
    private MyField jtxtOdir = null;

    //buttons
    private JButton jBtnDir = null;
    private JButton jBtnOdir = null;
    private JButton jBtnExecute = null;
    private JButton jBtnChecck= null;
    //private static JButton jBtnCancel = null;

    //progress bar
    private JProgressBar jProgress =     null;

    //check box
    private JCheckBox jchckslct = null;

    //radio button
    private JRadioButton UBrnchTxtF = null;
    private JRadioButton UHsChrgT = null;
    private JRadioButton Bank = null;
    private ButtonGroup BttnGroupUpdType = new ButtonGroup();

    static String inDir = "";
    static String outDir = "";
    static String dirPath = "";
    static BufferedReader inRec = null;
    static String diropen = null;

    /*********************
     *** File variable ***
     *********************/
    static Statement stmt = null;
    static ResultSet rs = null;

    //UBrnchTxtF BdateUpdated
    private static String ABdateUpdated = "";
    private static String BcustAccntNum = "";
    private static String BcustAccntName = "";
    private static String BcustAccntNameShort = "";
    private static String Baddress1 = "";
    private static String BtelNo = "";
    private static String BfaxNo = "";
    private static String BcontPerson = "";
    private static String BtinNo = "";
    private static String BvatExFlag = "";
    private static String BhCFlag = "";
    private static int   BallBrchsFlag;
    private static String BactiveFlag = "";
    private static double BcreditLimit = 0.0;
    private static String BbranchNum = "";
    private static String BbNum = "";
    private static String BaccntType = "";
    private static double BtotalTxnAmnt = 0.0;
    private static double BtotalPayAmnt = 0.0;
    private static double BtotalCAmnt = 0.0;
    private static double BtotalDAmnt = 0.0;
    private static double Bbal = 0.0;
    private static String BdateUpdated = "";
    private static String Beffdate = "";
    private static String Bexdate = "";

    private static String terminalNum = "";
    private static String invoiceNum = "";
    private static String custAccntNum = "";
    private static String custbNum="";
    private static String txnNum = "";
    private static String trxnAmnt = "";
    private static String txnType = "";
    private static String empNum = "";
    private static String empFName = "";
    private static String empLName = "";
    private static String empMInitail = "";

    //  Bank
    private static String bBCode = "";
    private static String bBDesc= "";

    static int recCnt = 0;
    static int maxValue = 0;
    static String inData = null;
    static String rename = null;
    static File currDirPath;
    static String[] files;
    static String upfile = null;
    static String backfile = null;
    static String backfile1 = null;

    static String sourceName;
    static String copyName;
    static String copyName1;
    static InputStream source;  
    static OutputStream copy;   
    static boolean force;  
    static int byteCount; 
    static File DirPath;

    private JPanel listpan = null;
    private JScrollPane pane = null;
    private JList list = null;
    private DefaultListModel model = new DefaultListModel();
    private JDirectoryChooser chooser;
    private static String query = null;
    public static int subMain = 0;

    private DateComboBox jcDate;
    private JComboBox jcboBranch = null;
    private JLabel jlblSelected = null;
    private static String code = null;
    private static String datehc = null;
    private String datehc1;
    private int chosenfile1 = 0;
    private String chosenfile;
    ArrayList<String > FILES;
    private static String dateinsert = null;
    private static int custTxnNum = 0;

    private static boolean exist = false;

    public fileUploader() {
        super("File Uploader", false, 
                true,  //closable 
                false, //icon 
                true); //minimizeable
        this.setName("fileUpload");
        initialize();
    }
    private void initialize() {
        this.setSize(310, 230);
        this.setTitle("File Uploader");
        this.setResizable(false);
        this.setVisible(true);
        this.setContentPane(getJContentPane());
        this.addInternalFrameListener(new InternalFrameListener(){
            public void internalFrameActivated(InternalFrameEvent arg0) {
                if  (subMain == 1){
                    try {
                        Sub.iFrame.setSelected(true);
                    }
                    catch (PropertyVetoException e) {}
                }
                mainform.tree.setEnabled(false);
                mainform.tree.clearSelection();
            }
            public void internalFrameClosed(InternalFrameEvent arg0) {}
            public void internalFrameClosing(InternalFrameEvent arg0) {
                mainform.tree.setEnabled(true);
            }
            public void internalFrameDeactivated(InternalFrameEvent arg0) {
                mainform.tree.setEnabled(true);
            }
            public void internalFrameDeiconified(InternalFrameEvent arg0) {}
            public void internalFrameIconified(InternalFrameEvent arg0) {}
            public void internalFrameOpened(InternalFrameEvent arg0) {}
        });
    }   
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jlblSelected = new JLabel();
            jlblSelected.setHorizontalAlignment(SwingConstants.LEFT);
            jlblSelected.setFont(new Font("Dialog", Font.BOLD, 12));
            jlblSelected.setText("Select a Branch");
            jlblSelected.setBounds(10, 20, 450, 22);
            jlblSelected.setVisible(false);

            jlblLocation = new JLabel();
            jlblLocation.setBounds(10, 130, 450, 22);
            jlblLocation.setText("File Directory");
            jlblLocation.setFont(new Font("Tahoma", Font.BOLD, 12));
            jlblLocation.grabFocus();
            jlblLocation.setVisible(false);

            jlblOdir = new JLabel();
            jlblOdir.setBounds(10, 160, 450, 22);
            jlblOdir.setText("Backup Directory");
            jlblOdir.setFont(new Font("Tahoma", Font.BOLD, 12));
            jlblOdir.grabFocus();       
            jlblOdir.setVisible(false);

            jlblFile = new JLabel();
            jlblFile.setBounds(70, 208, 200, 20);
            jlblFile.setText("File/s");
            jlblFile.setFont(new Font("Tahoma", Font.BOLD, 12));
            jlblFile.grabFocus();
            jlblFile.setVisible(false);

            jlblSdate = new JLabel();
            jlblSdate.setBounds(7, 80, 90, 23);
            jlblSdate.setText("Select Date:");
            jlblSdate.setFont(new Font("Tahoma", Font.BOLD, 12));
            jlblSdate.grabFocus();

            jProgress = new JProgressBar();
            jProgress.setBounds(90, 120, 200, 21);
            jProgress.setStringPainted(true);
            jProgress.setFont(new Font("Tahoma", Font.BOLD, 14));
            jProgress.setValue(0);
            jProgress.setVisible(false);
        }
        jContentPane = new JPanel();
        jContentPane.setLayout(null);
        jContentPane.add(getjcboBranch(), null);

        jContentPane.add(jlblSelected, null);
        jContentPane.add(jlblFile, null);
        jContentPane.add(jlblLocation, null);
        jContentPane.add(jlblOdir, null);
        jContentPane.add(jlblSdate, null);

        jContentPane.add(jProgress, null);

        jContentPane.add(getJTxtDir(), null);
        jContentPane.add(getJBtnDir(), null);
        jContentPane.add(getJTxtOdir(), null);
        jContentPane.add(getJBtnOdir(), null);

        jContentPane.add(getPane(), null);

        jContentPane.add(getJCheckBox(), null);

        jContentPane.add(getJBtnExecute(), null);   
        jContentPane.add(getJBtnCheck(), null); 

        jContentPane.add(getJRadioUBrnchTxtF(), null);
        jContentPane.add(getJRadioUHsChrgT(), null);
        jContentPane.add(getJRadioHsChrgA(), null);

        BttnGroupUpdType.add(getJRadioUBrnchTxtF());
        BttnGroupUpdType.add(getJRadioUHsChrgT());
        BttnGroupUpdType.add(getJRadioHsChrgA());
        getButtonUpdType();

        jContentPane.add(getDate(), null);

        return jContentPane;
    }

    private JComboBox getjcboBranch(){
        if(jcboBranch == null){
            jcboBranch = new JComboBox();
            jcboBranch.setBounds(new Rectangle(120, 20, 200, 22));
            jcboBranch.setVisible(false);
            try{
            getBranch();
            jcboBranch.setSelectedIndex(0);
            code = jcboBranch.getSelectedItem().toString();
            }catch (NullPointerException e) {
                // TODO: handle exception
            }

        }

        return jcboBranch;
    }

    private ButtonGroup getButtonUpdType(){
        BttnGroupUpdType = new ButtonGroup();
        BttnGroupUpdType.add(UBrnchTxtF);
        BttnGroupUpdType.add(UHsChrgT);
        BttnGroupUpdType.add(Bank);
        return BttnGroupUpdType;
    }

    private DateComboBox getDate() {
        if (jcDate == null) {
            jcDate = new DateComboBox();
            jcDate.setBounds(new Rectangle(90, 80, 200, 23));
            jcDate.setEnabled(false);
            jcDate.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent arg0) {
                    jBtnExecute.setEnabled(false);
                    jBtnChecck.setEnabled(true);

                }

            }); 
        }
        return jcDate;
    }

    //UBrnchTxtF
    private JRadioButton getJRadioUBrnchTxtF() {
        if (UBrnchTxtF == null) {
            UBrnchTxtF = new JRadioButton();
            UBrnchTxtF.setBounds(new Rectangle(7, 10, 200, 16));
            UBrnchTxtF.setFont(new Font("Tahoma", Font.BOLD, 12));
            UBrnchTxtF.setText("Branch File");
            UBrnchTxtF.setSelected(false);
            UBrnchTxtF.setEnabled(true);
            UBrnchTxtF.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    try {
                        refresh();
                        getDateUpload1();
                        jProgress.setVisible(false);
                        jBtnDir.setEnabled(true);
                        jBtnOdir.setEnabled(true);
                        jtxtDir.setText(null);
                        jtxtOdir.setText(null);
                        jBtnChecck.setEnabled(false);

                        QueryPathhcTxn();

                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (UBrnchTxtF.isSelected() == true){
                        jcDate.setEnabled(false);   
                    }

                }               
            });
        }
        return UBrnchTxtF;
    }
    private JRadioButton getJRadioUHsChrgT() {
        if (UHsChrgT == null) {
            UHsChrgT = new JRadioButton();
            UHsChrgT.setBounds(new Rectangle(7, 30, 200, 16));
            UHsChrgT.setFont(new Font("Tahoma", Font.BOLD, 12));
            UHsChrgT.setText("House Charge");
            UHsChrgT.setSelected(false);
//          UHsChrgT.setEnabled(false);
            UHsChrgT.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    try{
                    Message.messageInfo("Choose Date");

                    jProgress.setVisible(false);
                    jBtnChecck.setEnabled(true);
                    }catch (Exception e) {
                        // TODO: handle exception
                    }
                    if (UHsChrgT.isSelected() == true){
                        jcDate.setEnabled(true);    
                    }

                }               
            });
        }
        return UHsChrgT;
      } 
    private JRadioButton getJRadioHsChrgA() {
        if (Bank == null) {
            Bank = new JRadioButton();
            Bank.setBounds(new Rectangle(7, 50, 200, 16));
            Bank.setFont(new Font("Tahoma", Font.BOLD, 12));
            Bank.setText("Bank Ref File");
            Bank.setSelected(false);
            Bank.setEnabled(true);
            Bank.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    try {
                        refresh();
                        jProgress.setVisible(false);
                        jBtnDir.setEnabled(true);
                        jBtnOdir.setEnabled(true);
                        jtxtDir.setText(null);
                        jtxtOdir.setText(null);
                        getDateUpload();
                        QueryPathhcTxn();
                        jBtnChecck.setEnabled(false);

                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (Bank.isSelected() == true){
                        jcDate.setEnabled(false);   
                    }

                }               
            });
        }
        return Bank;
      }

    private MyField getJTxtDir(){
        if(jtxtDir == null){
            jtxtDir = new MyField(true, 100);
            jtxtDir.setBounds(120, 130, 200, 22);
            jtxtDir.setText(inDir);
            jtxtDir.setEnabled(false);
            jtxtDir.setVisible(false);
            jtxtDir.addKeyListener(new KeyListener() {
                public void keyPressed(KeyEvent arg0) {
                }

                public void keyReleased(KeyEvent arg0) {
                }
                public void keyTyped(KeyEvent arg0) {
                }
            });
            jtxtDir.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent arg0) {
                }

                public void focusLost(FocusEvent arg0) {
                }
            });
        }
        return jtxtDir;
    }
    private MyField getJTxtOdir(){
        if(jtxtOdir == null){
            jtxtOdir = new MyField(true, 100);
            jtxtOdir.setBounds(120, 160, 200, 22);
            jtxtOdir.setText(outDir);
            jtxtOdir.setEnabled(false);
            jtxtOdir.setVisible(false);
            jtxtOdir.addKeyListener(new KeyListener() {
                public void keyPressed(KeyEvent arg0) {
                }

                public void keyReleased(KeyEvent arg0) {
                }
                public void keyTyped(KeyEvent arg0) {
                }
            });
            jtxtOdir.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent arg0) {
                }

                public void focusLost(FocusEvent arg0) {
                }
            });
        }
        return jtxtOdir;
    }

    private JButton getJBtnDir() {
        if (jBtnDir == null) {
            jBtnDir = new JButton();
            jBtnDir.setActionCommand("Upload");
            jBtnDir.setText("Browse...");
            jBtnDir.setFont(new Font("Tahoma", Font.BOLD, 10));
            jBtnDir.setBounds(330, 130, 85, 20);
            jBtnDir.setMnemonic(KeyEvent.VK_S);
            jBtnDir.setEnabled(false);
            jBtnDir.setVisible(false);
            jBtnDir.addActionListener(new ActionListener() {
                @SuppressWarnings("unchecked")
                public void actionPerformed(ActionEvent arg0) {
                    jProgress.setVisible(false);
                    chooser = new JDirectoryChooser(inDir);
                    int choice = chooser.showOpenDialog(jContentPane);
                    if(choice == JDirectoryChooser.CANCEL_OPTION) {
                        jtxtDir.setText(inDir);
                    }
                    else {
                        inDir = chooser.getSelectedFile().getAbsolutePath();
                        if (inDir.length() > 0) 
                            dirPath = inDir;
                        else
                            dirPath = System.getProperty("user.dir");
                            currDirPath = new File(inDir);

                        if(currDirPath.isDirectory() == false){
                            if (currDirPath.exists() == false)
                                JOptionPane.showMessageDialog(null, "There is no such directory!");
                              else
                                JOptionPane.showMessageDialog(null, "That file is not a directory.");
                        }else {
                            try{
                                model.removeAllElements();
                            }catch (NullPointerException e) {
                                // TODO: handle exception
                            }
                            /**************************
                             *** list specific date ***
                             **************************/
                            FILES = new ArrayList();

                            if (UBrnchTxtF.isSelected() == true){ //System.out.println("BROWSE");
                                    files = currDirPath.list();                     
                                    for (int i = 0; i < files.length; i++){
                                        if (files[i].startsWith("hc") || files[i].startsWith("HC") ){
                                            chosenfile1++;
                                            chosenfile = files[i];

                                            model.addElement(chosenfile); //System.out.println(chosenfile);
                                        }
                                    }
                            }else if (UHsChrgT.isSelected() == true){ //System.out.println("hehe");
                                files = currDirPath.list();                     
                                for (int i = 0; i < files.length; i++){
                                    if (files[i].startsWith("hscharge.dat") || files[i].startsWith("HSCHARGE.DAT") ){
                                        chosenfile1++;
                                        chosenfile = files[i];

                                        model.addElement(chosenfile); //System.out.println(chosenfile);
                                    }
                                }
                            }else if (Bank.isSelected() == true){ //System.out.println("h0h0");
                                files = currDirPath.list();                     
                                for (int i = 0; i < files.length; i++){
                                    if (files[i].startsWith("bk") || files[i].startsWith("BK")){
                                        chosenfile1++;
                                        chosenfile = files[i];
                                        FILES.add(chosenfile);
                                        model.addElement(chosenfile); //System.out.println(chosenfile);
                                    }
                                }
                            }
                            else{
                                    files = currDirPath.list();
                                    for (int i = 0; i < files.length; i++){
                                          model.addElement(files[i]); 
                                    }
                                }
//                            files = currDirPath.list();
//                            for (int i = 0; i < files.length; i++){
//                                    model.addElement(files[i]); 
//                            } 
                          }
                        jtxtDir.setText(inDir);
                        jchckslct.setSelected(false);
                        jBtnExecute.setText("Upload");
                        if (jtxtDir.getText().trim().length() > 0 && jtxtOdir.getText().trim().length() > 0)
                            jBtnExecute.setEnabled(true);
                        else
                            jBtnExecute.setEnabled(false);
                        if(list.getModel().getSize() == 0){
                            jBtnExecute.setText("Reload");
                            jBtnExecute.setMnemonic('R');
                            jchckslct.setSelected(true);
                            jchckslct.setEnabled(true);
                        }else{
                            jchckslct.setEnabled(true);
                        }
                    }//end of else if
                }   

            });

        }
        return jBtnDir;

    }
    private JButton getJBtnOdir() {
        if (jBtnOdir == null) {
            jBtnOdir = new JButton();
            jBtnOdir.setActionCommand("");
            jBtnOdir.setText("Browse...");
            jBtnOdir.setFont(new Font("Tahoma", Font.BOLD, 10));
            jBtnOdir.setBounds(330, 160, 85, 20);
            jBtnOdir.setMnemonic(KeyEvent.VK_S);
            jBtnOdir.setEnabled(false);
            jBtnOdir.setVisible(false);
            jBtnOdir.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    jProgress.setVisible(false);
                    chooser = new JDirectoryChooser();
                    int choice = chooser.showOpenDialog(jContentPane);
                    if(choice == JDirectoryChooser.CANCEL_OPTION) {
                        jtxtOdir.setText(outDir);
                    }
                    else {
                        outDir = chooser.getSelectedFile().getAbsolutePath();
                        if (outDir.length() > 0) 
                            dirPath = outDir;
                        else
                            dirPath = System.getProperty("user.dir");
                            currDirPath = new File(outDir);

                        if(currDirPath.isDirectory() == false){
                            if (currDirPath.exists() == false)
                                Message.messageError("There is no such directory!");
                              else
                                Message.messageError("That file is not a directory.");
                        }
                        jtxtOdir.setText(outDir);
                        jBtnExecute.setText("Upload");
                        jchckslct.setSelected(true);
                        if (jtxtDir.getText().trim().length() > 0 && jtxtOdir.getText().trim().length() > 0 )
                            jBtnExecute.setEnabled(true);
                        else
                            jBtnExecute.setEnabled(false);

                        if(list.getModel().getSize() == 0){
                            jBtnExecute.setText("Reload");
                            jBtnExecute.setMnemonic('R');
                            jchckslct.setSelected(true);
                            jchckslct.setEnabled(true);
                        }else{
                            jchckslct.setEnabled(true);
                        }
                    }
                }
            });
        }
        return jBtnOdir;
    }   
    private JCheckBox getJCheckBox() {
        jchckslct = new JCheckBox();
        jchckslct.setText("Select All");
        jchckslct.setFont(new Font("Tahoma", Font.BOLD, 12));
        jchckslct.setSize(new Dimension(100, 50));
        jchckslct.setLocation(new Point(330, 208));
        jchckslct.setEnabled(true);
        jchckslct.setSelected(true);
        jchckslct.setVisible(false);
        jchckslct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                jProgress.setVisible(false);
                if(jchckslct.isSelected() == true && jtxtDir.getText().trim().length() > 0 && jtxtOdir.getText().trim().length() > 0){
                    jBtnExecute.setEnabled(true);
                }

                int[] indices = new int[files.length];

                if(jchckslct.isSelected() == true){
                    int setQ = Message.messageYesNo("You select all the data");
                    if (setQ == JOptionPane.YES_OPTION){
                        jchckslct.setSelected(true);
                        if(list.getModel().getSize() == 0){
                            JOptionPane.showMessageDialog(null, "No Data Available");
                        }else{
                            for(int i=0; i<indices.length; i++){
                                indices[i]= i;
                            }
                        list.setSelectedIndices(indices);
                        }
                    }else{
                        list.setSelectedIndices(indices);
                        jchckslct.setSelected(true);
                    }
                   jProgress.setVisible(false);
                }else {
                    jProgress.setVisible(false);
                    list.setSelectedIndices(indices);
                }               
            }
        });
        return jchckslct;
    }
    private JButton getJBtnExecute() {
        if (jBtnExecute == null) {
            jBtnExecute = new JButton();
            jBtnExecute.setBounds(new Rectangle(90, 120, 200, 21));
            jBtnExecute.setFont(new Font("Tahoma", Font.BOLD, 14));
            jBtnExecute.setMnemonic('U');
            jBtnExecute.setText("Upload");
            jBtnExecute.setEnabled(false);
            if(list.getModel().getSize() == 0){
                jBtnExecute.setText("Reload");
                jBtnExecute.setMnemonic('R');
                jchckslct.setSelected(true);
                jchckslct.setEnabled(true);
            }else{
                jchckslct.setEnabled(true);
            }
            jBtnExecute.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    if(list.isSelectionEmpty() == true){
//                      JOptionPane.showMessageDialog(null, "Select File to Upload");
                    }
                    try{
                        if(jBtnExecute.getText().equalsIgnoreCase("Reload") == true){
                            reload();
                            jBtnExecute.setText("Upload");
                            jchckslct.setSelected(true);
                        }else if(jBtnExecute.getText().equalsIgnoreCase("Reload") == false){
//                          jcDate.setEnabled(true);
                            checkOdir();
                        }
                    }catch (NullPointerException e) {
                        // TODO: handle exception
                    }   
                    try{
//                      }
                        if(list.getModel().getSize() == 0){
                            jBtnExecute.setText("Reload");
                            jBtnExecute.setMnemonic('R');
                            jchckslct.setSelected(true);
                            jchckslct.setEnabled(true);
                        }else{
                            jchckslct.setEnabled(true);
                        }

                        if(list.getSelectedValue().toString().length() < 0){
                            list.setSelectedIndex(0);
                        }
                    }catch (NullPointerException e) {
                        // TODO: handle exception
                    }
                }
            });
        }
        return jBtnExecute;
    }

    private JButton getJBtnCheck() {
        if (jBtnChecck == null) {
            jBtnChecck = new JButton();
            jBtnChecck.setBounds(new Rectangle(90, 150, 200, 21));
            jBtnChecck.setFont(new Font("Tahoma", Font.BOLD, 14));
            jBtnChecck.setMnemonic('U');
            jBtnChecck.setText("Check Data");
            jBtnChecck.setEnabled(false);
            jBtnChecck.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    try {
//                      System.out.println("rdbutton");
                        refresh();
                        getDateUpload();
                        jProgress.setVisible(false);
                        jBtnDir.setEnabled(true);
                        jBtnOdir.setEnabled(true);
                        jtxtDir.setText(null);
                        jtxtOdir.setText(null);
//                      UHsChrgT.setEnabled(false);
//                      jBtnExecute.setEnabled(true);
                        QueryPathhcTxn();
//                      System.out.println("rdbuttonend");

                    }catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        return jBtnChecck;
    }
    private JPanel getPane() {
         listpan = new JPanel();
         listpan.setBounds(120, 208, 200, 200);
         pane = new JScrollPane();
         pane.setPreferredSize(listpan.getSize());
         pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
         pane.setVisible(false);
         listpan.add(pane);
         getList();     
         pane.getViewport().add(list);
        return listpan;
      }
    private JList getList(){
         list = new JList(model);
         list.setFixedCellWidth(330);
         list.setVisibleRowCount(20);
         list.setEnabled(false);
         list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
         list.addMouseListener(new MouseListener(){

            public void mouseClicked(MouseEvent arg0) {
                // TODO Auto-generated method stub
                if(list.getSelectedIndices().length < files.length){
                    jchckslct.setSelected(true);
                }

                jProgress.setVisible(false);
            }
            public void mouseEntered(MouseEvent arg0) {
                // TODO Auto-generated method stub              
            }
            public void mouseExited(MouseEvent arg0) {
                // TODO Auto-generated method stub              
            }
            public void mousePressed(MouseEvent arg0) {
                // TODO Auto-generated method stub              
            }
            public void mouseReleased(MouseEvent arg0) {
                // TODO Auto-generated method stub              
            }            
         });
         return list;
    }
    /**
     * @program - It reads textfile from the directory
     * @param inFile
     * @throws IOException
     */
    public void readTxtFile ( File inFile, File reFile ) throws IOException {
//      System.out.println("readtxt");
        NumberFormat NoFormat = NumberFormat.getInstance();
        try {
            inRec = new BufferedReader( new FileReader(inFile) );       
            while (( inData = inRec.readLine()) != null) {
                recCnt++;
            }
            inRec.close();
            maxValue = recCnt;
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (Exception err) {
            err.printStackTrace();
        }
        jProgress.setMinimum( 0 );
        jProgress.setMaximum( maxValue );
        jProgress.setValue( 0 );
        jProgress.setVisible(true);
        try {
            try{
                inRec = new BufferedReader( new FileReader(inFile) );
                stmt = DBConnect.getConnection().createStatement();
            }catch (FileNotFoundException e) {
                // TODO: handle exception
            }           
            txnCntr = 1;

            while ((inData = inRec.readLine()) != null) {
                jProgress.setString("Uploading in progress... "+NoFormat.format(txnCntr)+" of "+NoFormat.format(maxValue));
                jProgress.setValue( txnCntr );
                Rectangle progressRect = jProgress.getBounds();
                progressRect.x = 0;
                progressRect.y = 0;
                jProgress.paintImmediately( progressRect );             

                /***********************
                 *** Source Dat File ***
                 ***********************/   

                //BranchTextFile
                if(UBrnchTxtF.isSelected() == true){

                    String refile = reFile.toString();
                    int stn = refile.length() - 4;
                    int stn1 = refile.length() - 10;

                    String txndate1 = refile.substring( stn1, stn).trim();

                    String dyear = "20" + txndate1.substring(0, 2);
                    String dmonth = txndate1.substring(2, 4);
                    String dday = txndate1.substring(4, 6);

                    ABdateUpdated = dyear +"-"+ dmonth +"-"+ dday;

                    date1 = df.parse(ABdateUpdated);

//                  System.out.println(date1 + "date1");

                    if(inData.contains("") ||inData.length() == 314 ){
                        try{                                                                                                                                                                        //Length
                            BcustAccntNum =                     inData.substring(0, 6).trim();                                                                      //1         6           6
                            BbNum =                             inData.substring(6, 10).trim();                                                                 //2         3           9       
                            BcustAccntName =                checkData(inData.substring(10, 60).trim());                                                 //3         50      59
                            BcustAccntNameShort =       checkData(inData.substring(60, 70).trim());                                                 //4         30      89
                            Baddress1 =                             inData.substring(90, 120).trim();                                                               //5         30      119
                            BtelNo =                                inData.substring(120, 130).trim();                                                              //6         10      129
                            BfaxNo =                                inData.substring(130, 140).trim();                                                              //7         10      139
                            BcontPerson =                       inData.substring(140, 180).trim();                                                              //8         40      179 
                            BtinNo =                                inData.substring(180, 195).trim();                                                              //9         15      194
                            BvatExFlag =                        inData.substring(195, 196).trim();                                                              //10        1           195
                            BhCFlag =                               inData.substring(196, 197).trim();                                                              //11        1           196
                            BallBrchsFlag =                         Integer.parseInt(inData.substring(197, 198).trim());                                    //12        1           197
                            BactiveFlag =                       inData.substring(198, 199).trim();                                                              //13        1           198
                            BcreditLimit=                           Double.parseDouble(inData.substring(199, 212).trim())/100;                      //14        3           201
                            BaccntType =                        inData.substring(212, 215).trim();                                                              //15        11,2        214
                            BtotalTxnAmnt =                 Double.parseDouble(inData.substring(215, 228).trim())/100;                      //16        11,2        227
                            BtotalPayAmnt =                 Double.parseDouble(inData.substring(228, 241).trim())/100;                      //17        11,2        240
                            BtotalCAmnt =                       Double.parseDouble(inData.substring(241, 254).trim())/100;                      //18        11,2        253
                            BtotalDAmnt =                       Double.parseDouble(inData.substring(254, 267).trim())/100;                      //19        11,2        266
                            Bbal =                                  Double.parseDouble(inData.substring(267, 280).trim())/100;                      //20        11,2        279             

                        }catch(NumberFormatException nf){

                        }catch(NullPointerException np){

                        }
                        BdateUpdated =                              inData.substring(280, 290).toString().trim();                                           //21  6         285
                        Beffdate =                                      inData.substring(290, 300).toString().trim();                       
                        Bexdate =                                       inData.substring(300, 310).toString().trim();
                        BbranchNum =                                inData.substring(310, 314).toString().trim();

                        if (BdateUpdated.equalsIgnoreCase("0000-00-00") == true){
                            BdateUpdated = ABdateUpdated; 
                        }
                        if (Beffdate.equalsIgnoreCase("0000-00-00") == true){
                            Beffdate = ABdateUpdated;
                        }
                        if (Bexdate.equalsIgnoreCase("0000-00-00") == true){
                            Bexdate = ABdateUpdated;
                        }

//                      System.out.println(BcustAccntNum                    +"1                     "+ "custAccntNum");
//                      System.out.println(BbNum                                +"2                     "+ "bNum ");
//                      System.out.println(BcustAccntName                   +"3                     "+ "BcustAccntName");
//                      System.out.println(BcustAccntNameShort          +"4                     "+ "BcustAccntNameShort ");
//                      System.out.println(Baddress1                            +"5                 "+ "Baddress1");
//                      System.out.println(BtelNo                               +"6                 "+ "BtelNo");
//                      System.out.println(BfaxNo                               +"7                 "+ "BfaxNo");
//                      System.out.println(BcontPerson                      +"8                 "+ "BcontPerson ");
//                      System.out.println(BtinNo                                   +"9                 "+ "BtinNo ");
//                      System.out.println(BvatExFlag                           +"10                "+ "BvatExFlag ");
//                      System.out.println(BhCFlag                              +"11                "+ "BhCFlag");
//                      System.out.println(BallBrchsFlag                        +"12                "+ "BallBrchsFlag");
//                      System.out.println(BactiveFlag                          +"13                "+ "BactiveFlag");
//                      System.out.println(BcreditLimit                         +"14                "+ "BcreditLimit");
//                      System.out.println(BaccntType                           +"15                "+ "BaccntType");
//                      System.out.println(BcreditLimit                         +"16                "+ "BcreditLimit");
//                      System.out.println(BtotalTxnAmnt                        +"17                "+ "BtotalTxnAmnt");
//                      System.out.println(BtotalCAmnt                      +"18                "+ "BtotalCAmnt");
//                      System.out.println(BtotalDAmnt                      +"19                "+ "BtotalDAmnt");
//                      System.out.println(Bbal                                 +"20                "+ "Bbal");
//                      System.out.println(BdateUpdated                     +"21                "+ "BdateUpdated");
//                      System.out.println(Beffdate                             +"22                "+ "Beffdate");
//                      System.out.println(Bexdate                              +"23                "+ "Bexdate");
//                      System.out.println(BbranchNum                           +"24                "+ "BranchNum");


                        writingBrnchTxtF();
                    }
                    else{
                        inFile.renameTo(reFile);
                        jProgress.setVisible(false);
                        maxValue = 0;
                        Message.messageInfo("Wrong input of data");
                        //return;
                        }
                }
                //HCTxn
                else if(UHsChrgT.isSelected() == true){
//                  System.out.println("data get");

                    if(inData.contains("") ||inData.length() == 92){

//                      terminalNum = inData.substring(0, 3).trim();                            
//                      custAccntNum = inData.substring(3, 9).trim();
//                      custbNum = inData.substring(9, 13).trim();
//                      invoiceNum = inData.substring(13, 20).trim();                           
//                      txnNum = inData.substring(20, 26).trim();                               
//                      txnAmnt = Double.parseDouble(inData.substring(26, 36).trim())/100+"";   
//                      txnType = inData.substring(36, 37).trim();                              
//                      empNum = inData.substring(37, 47).trim();                               
//                      empFName = inData.substring(47, 67).trim();                             
//                      empLName = inData.substring(67, 87).trim();                             
//                      empMInitail = inData.substring(87, 88).trim();  

                        terminalNum = inData.substring(0, 3).trim();                            
                        custAccntNum = inData.substring(3, 9).trim();
                        custbNum = inData.substring(9, 13).trim();
                        invoiceNum = inData.substring(13, 23).trim();                           
                        txnNum = inData.substring(23, 29).trim();                               
                        trxnAmnt = Double.parseDouble(inData.substring(29, 39).trim())/100+"";  
                        txnType = inData.substring(39, 40).trim();                              
                        empNum = inData.substring(40, 50).trim();                               
                        empFName = inData.substring(50, 70).trim();                             
                        empLName = inData.substring(70, 90).trim();                             
                        empMInitail = inData.substring(90, 92).trim();

//                      System.out.println(terminalNum + " terminal number");
//                      System.out.println(custAccntNum+ "customer account number");
//                      System.out.println(custbNum+ "bnum");
//                      System.out.println(invoiceNum+ "invoice number");
//                      System.out.println(txnNum+ "transaction number");
//                      System.out.println(trxnAmnt+ "transaction amount");
//                      System.out.println(txnType+ "transaction type");
//                      System.out.println(empNum+ "emp num");
//                      System.out.println(empFName+ "emp name");
//                      System.out.println(empLName+ "emp last");
//                      System.out.println(empMInitail+ "midle ini");

                        custTxnNum();

                        writingCustTxnFile();
                        //new uploaderStoresales();                     
                    }
                    else{
                        inFile.renameTo(reFile);
                        jProgress.setVisible(false);
                        maxValue = 0;
                        Message.messageInfo("Wrong input of data");
                        //return,
                    }
                }
                //Bank
                else if(Bank.isSelected() == true){
                    if(inData.length() == 45){
                        bBCode = inData.substring(0, 15).toString().trim();
                        bBDesc = inData.substring(15, 45).toString().trim();
                        writingBank();
                    }
                    else{
                        inFile.renameTo(reFile);
                        jProgress.setVisible(false);
                        maxValue = 0;
                        Message.messageInfo("Wrong input of data");
                        //return;
                    }
                }
                //Deposit

                txnCntr++;              
            } // END OF while (( inData = inRec.readLine()) != null) 

            jProgress.setString("Finished Uploading");
            inRec.close();
            stmt.close();
            jProgress.setValue( maxValue );
            inFile.renameTo(reFile);
            if(UHsChrgT.isSelected() == false){
                backup();
            }
            if(jProgress.getString().equalsIgnoreCase("Finished Uploading")){
                AutoRefresh();
            }

        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
            inFile.renameTo(reFile);
        } catch (Exception err) {
            err.printStackTrace();
            inFile.renameTo(reFile);
        }
    } // END public static void readItemFile ( File inFile ) throws IOException 


    //UBrnchTxtF
    /********************************
    *** write UBrnchTxtF Dat File ***
    *********************************/  
    private void writingBrnchTxtF(){

        try{
            String query = DBConnect.Select("bCustMasterFile", "*", "custAccntNum = '"+DBConnect.clean(BcustAccntNum)+
                                                                                                            "' and bNum = '"+DBConnect.clean(BbNum)+"'", null);

            Statement stmt = DBConnect.getConnection().createStatement();
            ResultSet rs = stmt.executeQuery(query);

            System.out.println(jcboBranch.getSelectedItem().toString().trim().substring(0, 
                                            jcboBranch.getSelectedItem().toString().trim().indexOf("-")).trim());

            if (rs.last() == false){
//              System.out.println("walang account");
                if ( BallBrchsFlag == 0){
                    if (BbranchNum.toString().equalsIgnoreCase(jcboBranch.getSelectedItem().toString().trim().substring(0, 
                                                            jcboBranch.getSelectedItem().toString().trim().indexOf("-")).trim()) == true){
                        System.out.println("0");
                        insertbCustMasterFile();
                    }   
                }else if( BallBrchsFlag == 1 ){
                        System.out.println("1");
                        insertbCustMasterFile();
                }

            }else{
//              System.out.println("meron account");
                try{
                    date = rs.getDate("dateUpdated").toString();
                    date2 = df.parse(date);
//                  System.out.println(date2 + "DATE2");
                }catch (Exception e) {
                    // TODO: handle exception
                }

                if (date1.after(date2)){
//                  System.out.println("burahin ang account");
                    bCustMasterdelete();

                    if ( BallBrchsFlag == 0){
                        if (BbranchNum.toString().equalsIgnoreCase(jcboBranch.getSelectedItem().toString().trim().substring(0,
                                                                    jcboBranch.getSelectedItem().toString().trim().indexOf("-")).trim()) == true){
                            insertbCustMasterFile();
                        }   
                    }else if( BallBrchsFlag == 1 ){
                            insertbCustMasterFile();
                    }   
                }

            }

            rs.close();
            stmt.close();
        }catch (Exception e) {
            // TODO: handle exception
        }   
    }//END of private static void writingBrnchTxtF()

    private static void writingCustTxnFile(){
//      System.out.println("writing");
        Statement st = null;
        ResultSet rs = null;
        String hcTxn = null;

        today = new Date();
        output = dateformat.format(today);
//      System.out.println(output);

        try{
            st = DBConnect.getConnection().createStatement();

            rs = st.executeQuery("  SELECT custAccntNum,bNum " +
                                                "   FROM branchCustTxnFile " +
                                                "   WHERE custAccntNum = '" + custAccntNum + "' " +
                                                "   AND bNum = '" + custbNum + "' " +
                                                "   AND hcTxnNum = '" +custTxnNum+"' " );
//          
//          System.out.println("SELECT custAccntNum, bNum " +
//                               "  FROM branchCustTxnFile " +
//                               " WHERE custAccntNum = '" + custAccntNum + "' " +
//                               "   AND bNum = '" + custbNum + "' " +
//                               "   AND hcTxnNum = '" +custTxnNum+"' " );

//          queryexist();
//          if (exist == true){
//                 Message.messageInfo("Data Already Uploded");
//          }else{
            if (rs.last() == false) {
                if(txnType.equalsIgnoreCase("1")){
                    trxnAmnt = "-"+trxnAmnt;
                }
                hcTxn = "INSERT INTO branchCustTxnFile (" +
                "terminalNum,inVoice," +
                "txnNum,docNum," +
                "txnType, custAccntNum,bNum," +
                "empIDNum, empFirstName, empLastName, empMiddleInitial," +
                "txnAmnt,creditAmnt, amntPaid, bal," +
                "hcTxnNum, txnDate,debitAmnt, branchCode )"+ //postDate)" +
                "VALUES (" +
//              " '"+txnDate+"', " +
                " '"+terminalNum+"', " +            //TERMINA NUMBER
                " '"+"0"+"', " +                        //INVOICE NUMBER
                " '"+txnNum+"', " +                 //TRANSACTION NUMBER
                " '"+invoiceNum+"', " +         //DOCNUM
                " '"+txnType+"', " +                    //TRANSACTION TYPE
                " '"+custAccntNum+"', " +       //CUSTOMER ACCOUNT NUMBER
                " '"+custbNum+"', " +               //BNUM
                " '"+empNum+"', " +             //EMPLOYEE NUMBER
                " '"+empFName+"', " +           //EMPLOYEE FIRST NAME
                " '"+empLName+"', " +           //EMPLOYEE LAST NAME
                " '"+empMInitail+"', " +            //EMPLOYEE MIDLE INITIAL
                " '"+trxnAmnt+"', " +               //TRANSACTION AMOUNT
                " '"+"0"+"', " +                        //CREDIT LIMIT AMOUNT
                " '"+"0"+"', " +                        //AMOUNT PAID
                " '"+trxnAmnt+"', "+                //BAL
                " '"+custTxnNum+""+"', " +      //CUSTOMER NUMBER
                " '"+dateinsert+"', " +             //TRANSACTION DATE  
                " '"+"0"+"', " +                        //DEBIT AMOUNT
                " '"+code.toString().trim().substring(0, code.toString().trim().indexOf("-")).trim()+"'"  + ")";

                System.out.println(terminalNum);
                System.out.println(invoiceNum);
                System.out.println(txnNum);
                System.out.println(txnType);
                System.out.println(custAccntNum);
                System.out.println(custbNum);
                System.out.println(empNum);
                System.out.println(empFName);
                System.out.println(empLName);
                System.out.println(empMInitail);
                System.out.println(trxnAmnt);
                System.out.println(custTxnNum);
                System.out.println(dateinsert);

//              System.out.println(custTxnNum   + " HC transaction number");
//              System.out.println(dateinsert       + "date inserted");
//              System.out.println(terminalNum  + " terminal number");
//              System.out.println(custAccntNum + "customer account number");
//              System.out.println(custbNum     + "bnum");
//              System.out.println(invoiceNum       + "invoice number - docnum");
//              System.out.println(txnNum           + "transaction number");
//              System.out.println(trxnAmnt         + "transaction amount");
//              System.out.println(txnType          + "transaction type");
//              System.out.println(empNum           + "emp num");
//              System.out.println(empFName     + "emp name");
//              System.out.println(empLName     + "emp last");
//              System.out.println(empMInitail      + "midle ini");

                st.execute(hcTxn);
                updateCustMasterFile();
                updatesysFile();
                }
            st.close();
            rs.close();
        }catch (SQLException e) {
//          Message.messageError("Data Already Uploaded!");
//          e.printStackTrace();
        }catch(Exception ex){
        }



    }//END of private void writingCustTxnFile() 

    private static void writingBank(){
        Statement st = null;
        Statement st1 = null;
        ResultSet rs = null;
        try{
            st = DBConnect.getConnection().createStatement();   
            st1 = DBConnect.getConnection().createStatement();      
            rs = st.executeQuery("SELECT bankCode " +
                     "  FROM bankRefFile " +
                     " WHERE bankCode = '" + bBCode + "'" );

            if (rs.last() == true) {
            }else{
                MySQL = DBConnect.Insert("bankRefFile", 
                        "bankCode, bankDesc", 
                        " '"+bBCode+"', " +
                        " '"+bBDesc+"' " );
                st1.execute(MySQL);
                st1.close();
            }


            st.close();
            rs.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }//END of private static void writingECouponTxn()               

    /*******************************************************
     *** @param - inDate                                                                            ***
     *** @return - Use to format Date (yyyy-MM-dd)                               ***
     ******************************************************/    
    private void backup() throws FileNotFoundException{
        sourceName = rename;
        copyName = backfile;    
        copyName1 = backfile1;  
        try {
             source = new FileInputStream(sourceName);
          }
          catch (FileNotFoundException e) {
//           System.out.println("Can't find file \"" + sourceName + "\".");
             return;
          }  

          if (UHsChrgT.isSelected() == true){
              File file1 = new File(copyName1);
              if(file1.mkdirs()){
//                System.out.println("Directory Created");
              }
              else{
//                System.out.println("Directory is not created");
              }

          }

          File file = new File(copyName);
          if (file.exists() && force == false) {
//            System.out.println(
//                 "Output file exists.  Use the -f option to replace it.");
              return;  
          }

          try {
              copy = new FileOutputStream(copyName);
           }
           catch (IOException e) {
//            System.out.println("Can't open output file \"" + copyName + "\".");
              return;
           }           
           try {
               while (true) {
                  int data = source.read();
                  if (data < 0)
                     break;
                  copy.write(data);
                  byteCount++;
               }
               source.close();
               copy.close();
            }
            catch (Exception e) {
               System.out.println("Error occurred while copying.  "
                                  + byteCount + " bytes copied.");
               System.out.println("Error: " + e);
            }
    }
    @SuppressWarnings("unchecked")
    private void reload(){
        list.removeAll();
        File dirpath = new File(jtxtDir.getText().trim());
        jBtnExecute.setEnabled(true);
        FILES = new ArrayList();

        if (UHsChrgT.isSelected() == true){
            try{
                files = currDirPath.list();                     
                for (int i = 0; i < files.length; i++){
                    if (files[i].startsWith("hscharge.dat") || files[i].startsWith("HSCHARGE.DAT")){
                        chosenfile1++;
                        chosenfile = files[i];
                        model.addElement(chosenfile); 
                    }
                }
            }catch (NullPointerException e) {
                // TODO: handle exception
                Message.messageError("No More Data Available");
            }
            if(list.getModel().getSize() == 0)
                Message.messageError("No More Data Available");     

        }else if(UBrnchTxtF.isSelected() == true){
            try{
                files = currDirPath.list();                     
                for (int i = 0; i < files.length; i++){
                    if (files[i].startsWith("hc" ) || files[i].startsWith("HC" )){
                        chosenfile1++;
                        chosenfile = files[i];

                        model.addElement(chosenfile); 
                    }
                }
            }catch (NullPointerException e) {
                // TODO: handle exception
                Message.messageError("No More Data Available");
            }
            if(list.getModel().getSize() == 0)
                Message.messageError("No More Data Available");     
        }else if(Bank.isSelected() == true){
            try{
                files = currDirPath.list();                     
                for (int i = 0; i < files.length; i++){
                    if (files[i].startsWith("bk") || files[i].startsWith("BK")){
                        chosenfile1++;
                        chosenfile = files[i];
                        FILES.add(chosenfile);
                        model.addElement(chosenfile); 
                    }
                }
            }catch (NullPointerException e) {
                // TODO: handle exception
                Message.messageError("No More Data Available");
            }
            if(list.getModel().getSize() == 0)
                Message.messageError("No More Data Available");     
        }else{
            try{
                files = dirpath.list();
                for (int i = 0; i < files.length; i++){
                  if (!files[i].endsWith(".txt") == true){
                      model.addElement(files[i]);
                  }  
                }
            }catch (NullPointerException e) {
                // TODO: handle exception
                Message.messageError("No More Data Available");
            }
            if(list.getModel().getSize() == 0)
                Message.messageError("No More Data Available");     
        }

    }   

    @SuppressWarnings("unchecked")
    private void QueryPathhcTxn(){
        Statement st = null;
        ResultSet rs = null;

        try{

//          System.out.println(jcboBranch.getSelectedItem().toString());

            st = DBConnect.getConnection().createStatement();           
            query = "SELECT dirTxtFileTxn, dirTxtFileArchive, dirBCustFile, bankdirFile " +
            "  FROM branchSysFile " +
            " WHERE branchCode = '"+ jcboBranch.getSelectedItem().toString().trim().substring(0, 
                                                        jcboBranch.getSelectedItem().toString().trim().indexOf("-")).trim() +"'";       
            MySQL = query;
            rs = st.executeQuery(MySQL);            
            while(rs.next()){
                if (UHsChrgT.isSelected() == true){

                    jtxtDir.setText(checkData(rs.getString(1))+ "/" + datehc);

                }else if(UBrnchTxtF.isSelected() == true){

                    jtxtDir.setText(checkData(rs.getString(3)));

                }else if(Bank.isSelected() == true){

                    jtxtDir.setText(checkData(rs.getString(3)));

                }

                jtxtOdir.setText(rs.getString(2));
            }
            rs.close();
            st.execute(MySQL);
            st.close();         
        }catch (Exception e) {
            e.printStackTrace();
        } finally {
        }       
        if(jtxtDir.getText().trim() == null) {
            jtxtDir.setText(inDir);
        }
        else {
            inDir = jtxtDir.getText().trim();   
            currDirPath = new File(inDir);
            if(currDirPath.isDirectory() == false){
                if (currDirPath.exists() == false){
                    JOptionPane.showMessageDialog(null, "No Data Available for this Date");
                    UHsChrgT.setSelected(false);
                    UBrnchTxtF.setSelected(false);
                }
                  else
                    JOptionPane.showMessageDialog(null, "That file is not a directory.");
            }else {
                try{
                    model.removeAllElements();
                }catch (NullPointerException e) {
                    // TODO: handle exception
                }   
                    /**************************
                     *** list specific date ***
                  
public void readTxtFile ( File inFile, File reFile ) throws IOException {
//		System.out.println("readtxt");
		NumberFormat NoFormat = NumberFormat.getInstance();
		try {
			inRec = new BufferedReader( new FileReader(inFile) );		
			while (( inData = inRec.readLine()) != null) {
				recCnt++;
			}
			inRec.close();
			maxValue = recCnt;
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		} catch (Exception err) {
			err.printStackTrace();
		}
		jProgress.setMinimum( 0 );
		jProgress.setMaximum( maxValue );
		jProgress.setValue( 0 );
		jProgress.setVisible(true);
		try {
			try{
				inRec = new BufferedReader( new FileReader(inFile) );
				stmt = DBConnect.getConnection().createStatement();
			}catch (FileNotFoundException e) {
				// TODO: handle exception
			}			
			txnCntr = 1;
			
			while ((inData = inRec.readLine()) != null) {
				jProgress.setString("Uploading in progress... "+NoFormat.format(txnCntr)+" of "+NoFormat.format(maxValue));
				jProgress.setValue( txnCntr );
				Rectangle progressRect = jProgress.getBounds();
				progressRect.x = 0;
				progressRect.y = 0;
				jProgress.paintImmediately( progressRect );				

				/***********************
				 *** Source Dat File ***
				 ***********************/	
				
				//BranchTextFile
				if(UBrnchTxtF.isSelected() == true){
					
					String refile = reFile.toString();
					int stn = refile.length() - 4;
					int stn1 = refile.length() - 10;
					
					String txndate1 = refile.substring( stn1, stn).trim();
					
					String dyear = "20" + txndate1.substring(0, 2);
					String dmonth = txndate1.substring(2, 4);
					String dday = txndate1.substring(4, 6);
					
					ABdateUpdated = dyear +"-"+ dmonth +"-"+ dday;
			
					date1 = df.parse(ABdateUpdated);
				
//					System.out.println(date1 + "date1");
					
					if(inData.contains("") ||inData.length() == 314 ){
						try{																																									    //Length
							BcustAccntNum = 					inData.substring(0, 6).trim();																		//1			6			6
							BbNum =								inData.substring(6, 10).trim();																	//2			3			9		
							BcustAccntName = 				checkData(inData.substring(10, 60).trim());													//3			50		59
							BcustAccntNameShort = 		checkData(inData.substring(60, 70).trim());													//4			30		89
							Baddress1 = 							inData.substring(90, 120).trim();																//5			30		119
							BtelNo = 								inData.substring(120, 130).trim();																//6			10		129
							BfaxNo =								inData.substring(130, 140).trim();																//7			10		139
							BcontPerson = 						inData.substring(140, 180).trim();																//8			40		179	
							BtinNo = 								inData.substring(180, 195).trim();																//9			15		194
							BvatExFlag = 						inData.substring(195, 196).trim();																//10		1			195
							BhCFlag	= 								inData.substring(196, 197).trim();																//11		1			196
							BallBrchsFlag = 						Integer.parseInt(inData.substring(197, 198).trim());									//12		1			197
							BactiveFlag = 						inData.substring(198, 199).trim();																//13		1			198
							BcreditLimit=							Double.parseDouble(inData.substring(199, 212).trim())/100;						//14 		3			201
							BaccntType = 						inData.substring(212, 215).trim();																//15 		11,2		214
							BtotalTxnAmnt =					Double.parseDouble(inData.substring(215, 228).trim())/100;						//16 		11,2		227
							BtotalPayAmnt =					Double.parseDouble(inData.substring(228, 241).trim())/100;						//17 		11,2		240
							BtotalCAmnt =						Double.parseDouble(inData.substring(241, 254).trim())/100;						//18 		11,2		253
							BtotalDAmnt =						Double.parseDouble(inData.substring(254, 267).trim())/100;						//19 		11,2		266
							Bbal =									Double.parseDouble(inData.substring(267, 280).trim())/100;						//20 		11,2		279 			
							
						}catch(NumberFormatException nf){
							
						}catch(NullPointerException np){
							
						}
						BdateUpdated =								inData.substring(280, 290).toString().trim();											//21  6			285
						Beffdate =										inData.substring(290, 300).toString().trim();						
						Bexdate =										inData.substring(300, 310).toString().trim();
						BbranchNum = 								inData.substring(310, 314).toString().trim();
						
						if (BdateUpdated.equalsIgnoreCase("0000-00-00") == true){
							BdateUpdated = ABdateUpdated; 
						}
						if (Beffdate.equalsIgnoreCase("0000-00-00") == true){
							Beffdate = ABdateUpdated;
						}
						if (Bexdate.equalsIgnoreCase("0000-00-00") == true){
							Bexdate = ABdateUpdated;
						}
						
//						System.out.println(BcustAccntNum 					+"1 					"+ "custAccntNum");
//						System.out.println(BbNum		 						+"2 					"+ "bNum ");
//						System.out.println(BcustAccntName	 				+"3 					"+ "BcustAccntName");
//						System.out.println(BcustAccntNameShort 			+"4 					"+ "BcustAccntNameShort ");
//						System.out.println(Baddress1 							+"5					"+ "Baddress1");
//						System.out.println(BtelNo 								+"6					"+ "BtelNo");
//						System.out.println(BfaxNo								+"7					"+ "BfaxNo");
//						System.out.println(BcontPerson 						+"8					"+ "BcontPerson	");
//						System.out.println(BtinNo									+"9					"+ "BtinNo ");
//						System.out.println(BvatExFlag 							+"10 				"+ "BvatExFlag ");
//						System.out.println(BhCFlag 								+"11 				"+ "BhCFlag");
//						System.out.println(BallBrchsFlag 						+"12 				"+ "BallBrchsFlag");
//						System.out.println(BactiveFlag							+"13 				"+ "BactiveFlag");
//						System.out.println(BcreditLimit							+"14 				"+ "BcreditLimit");
//						System.out.println(BaccntType							+"15 				"+ "BaccntType");
//						System.out.println(BcreditLimit							+"16				"+ "BcreditLimit");
//						System.out.println(BtotalTxnAmnt						+"17 				"+ "BtotalTxnAmnt");
//						System.out.println(BtotalCAmnt						+"18 				"+ "BtotalCAmnt");
//						System.out.println(BtotalDAmnt						+"19				"+ "BtotalDAmnt");
//						System.out.println(Bbal									+"20 				"+ "Bbal");
//						System.out.println(BdateUpdated						+"21 				"+ "BdateUpdated");
//						System.out.println(Beffdate								+"22 				"+ "Beffdate");
//						System.out.println(Bexdate								+"23 				"+ "Bexdate");
//						System.out.println(BbranchNum   						+"24				"+ "BranchNum");
						
						
						writingBrnchTxtF();
					}
					else{
						inFile.renameTo(reFile);
						jProgress.setVisible(false);
						maxValue = 0;
						Message.messageInfo("Wrong input of data");
						//return;
						}
				}
				//HCTxn
				else if(UHsChrgT.isSelected() == true){
//					System.out.println("data get");
									
					if(inData.contains("") ||inData.length() == 92){
						
//						terminalNum = inData.substring(0, 3).trim(); 							
//						custAccntNum = inData.substring(3, 9).trim();
//						custbNum = inData.substring(9, 13).trim();
//						invoiceNum = inData.substring(13, 20).trim();							
//						txnNum = inData.substring(20, 26).trim();								
//						txnAmnt = Double.parseDouble(inData.substring(26, 36).trim())/100+"";	
//						txnType = inData.substring(36, 37).trim();								
//						empNum = inData.substring(37, 47).trim();								
//						empFName = inData.substring(47, 67).trim();								
//						empLName = inData.substring(67, 87).trim();								
//						empMInitail = inData.substring(87, 88).trim();	
						
						terminalNum = inData.substring(0, 3).trim(); 							
						custAccntNum = inData.substring(3, 9).trim();
						custbNum = inData.substring(9, 13).trim();
						invoiceNum = inData.substring(13, 23).trim();							
						txnNum = inData.substring(23, 29).trim();								
						trxnAmnt = Double.parseDouble(inData.substring(29, 39).trim())/100+"";	
						txnType = inData.substring(39, 40).trim();								
						empNum = inData.substring(40, 50).trim();								
						empFName = inData.substring(50, 70).trim();								
						empLName = inData.substring(70, 90).trim();								
						empMInitail = inData.substring(90, 92).trim();
						
//						System.out.println(terminalNum + " terminal number");
//						System.out.println(custAccntNum+ "customer account number");
//						System.out.println(custbNum+ "bnum");
//						System.out.println(invoiceNum+ "invoice number");
//						System.out.println(txnNum+ "transaction number");
//						System.out.println(trxnAmnt+ "transaction amount");
//						System.out.println(txnType+ "transaction type");
//						System.out.println(empNum+ "emp num");
//						System.out.println(empFName+ "emp name");
//						System.out.println(empLName+ "emp last");
//						System.out.println(empMInitail+ "midle ini");

						custTxnNum();
						
						writingCustTxnFile();
						//new uploaderStoresales();						
					}
					else{
						inFile.renameTo(reFile);
						jProgress.setVisible(false);
						maxValue = 0;
						Message.messageInfo("Wrong input of data");
						//return,
					}
				}
				//Bank
				else if(Bank.isSelected() == true){
					if(inData.length() == 45){
						bBCode = inData.substring(0, 15).toString().trim();
						bBDesc = inData.substring(15, 45).toString().trim();
						writingBank();
					}
					else{
						inFile.renameTo(reFile);
						jProgress.setVisible(false);
						maxValue = 0;
						Message.messageInfo("Wrong input of data");
						//return;
					}
				}
				//Deposit
				
				txnCntr++;				
			} // END OF while (( inData = inRec.readLine()) != null) 
			
			jProgress.setString("Finished Uploading");
			inRec.close();
			stmt.close();
			jProgress.setValue( maxValue );
			inFile.renameTo(reFile);
			if(UHsChrgT.isSelected() == false){
				backup();
			}
			if(jProgress.getString().equalsIgnoreCase("Finished Uploading")){
				AutoRefresh();
			}
			
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
			inFile.renameTo(reFile);
		} catch (Exception err) {
			err.printStackTrace();
			inFile.renameTo(reFile);
		}
	} // END public static void readItemFile ( File inFile ) throws IOException
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.