Jump to content

How can I let the text inside a text file ...

- - - - -

  • Please log in to reply
1 reply to this topic

#1
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
When I open the file using Jbutton the text inside the file will appear in my textbox ?

here's my code :
 private void OpenFileActionPerformed(java.awt.event.ActionEvent evt) {                                         

       JFileChooser chooser = new JFileChooser();

        chooser.setCurrentDirectory(new File("."));

        chooser.setDialogTitle("Select configuration file");

        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        chooser.setAcceptAllFileFilterUsed(false);


        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)

        {

            File f = new File(chooser.getSelectedFile().getAbsolutePath());

            if (f.exists())

            {

                LoadSMILEFile(chooser.getSelectedFile().getAbsolutePath());

                JOptionPane.showMessageDialog(null, "Configuration loaded", "Loaded", JOptionPane.INFORMATION_MESSAGE);

            }

            else

            {

                JOptionPane.showMessageDialog(null, "File does not exists", "Error", JOptionPane.ERROR_MESSAGE);

            }

        }

}

 private void LoadSMILEFile(String absolutePath) {

       

            Properties configFile = new Properties();

    }

         


    

    }

}


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
If the file is pure text, then I think you can work with a Scanner.

File f;

...

Scanner scanner = new Scanner(f);

while(scanner.hasNextLine()){

  textBox.setText(textBox.getText() + scanner.nextLine());

}

Maybe you need to add '\n' after every line.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users