Pages

Java Read File In To Text Area

//filechooser draganddrop as global feature
fileChooser.setCurrentDirectory(new File(Util.getUtil().getUserDirectory() + "\\logs"));

 int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            lblURI.setText(fileChooser.getSelectedFile().getPath());
            File file = fileChooser.getSelectedFile();
            try {
                // What to do with the file, e.g. display it in a TextArea
                textarea.read(new FileReader(file.getAbsolutePath()), null);
                btnSend.requestFocus();
            } catch (Exception e) {
                LogFile.log(getClass().getName(), "btnOpenActionPerformed", e.getMessage().toString(), rootPane);
            }
        } else {
            System.out.println("File access cancelled by user.");
        }

No comments:

Post a Comment