How to get the content of text file to write in JTextArea?

Hello,
I have text area and File chooser..
i wanna the content of choosed file to be written into text area..
I have this code:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.*;
public class Test_Stemmer extends JFrame {
public Test_Stemmer() {
super("Arabic Stemmer..");
setSize(350, 470);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JButton openButton = new JButton("Open");
JButton saveButton = new JButton("Save");
JButton dirButton = new JButton("Pick Dir");
JTextArea ta=new JTextArea("File will be written here", 10, 25);
JTextArea ta2=new JTextArea("Stemmed File will be written here", 10, 25);
final JLabel statusbar =
              new JLabel("Output of your selection will go here");
// Create a file chooser that opens up as an Open dialog
openButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent ae) {
     JFileChooser chooser = new JFileChooser();
     chooser.setMultiSelectionEnabled(true);
     int option = chooser.showOpenDialog(Test_Stemmer.this);
     if (option == JFileChooser.APPROVE_OPTION) {
       File[] sf = chooser.getSelectedFiles();
       String filelist = "nothing";
       if (sf.length > 0) filelist = sf[0].getName();
       for (int i = 1; i < sf.length; i++) {
         filelist += ", " + sf.getName();
statusbar.setText("You chose " + filelist);
else {
statusbar.setText("You canceled.");
// Create a file chooser that opens up as a Save dialog
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser = new JFileChooser();
int option = chooser.showSaveDialog(Test_Stemmer.this);
if (option == JFileChooser.APPROVE_OPTION) {
statusbar.setText("You saved " + ((chooser.getSelectedFile()!=null)?
chooser.getSelectedFile().getName():"nothing"));
else {
statusbar.setText("You canceled.");
// Create a file chooser that allows you to pick a directory
// rather than a file
dirButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int option = chooser.showOpenDialog(Test_Stemmer.this);
if (option == JFileChooser.APPROVE_OPTION) {
statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
chooser.getSelectedFile().getName():"nothing"));
else {
statusbar.setText("You canceled.");
c.add(openButton);
c.add(saveButton);
c.add(dirButton);
c.add(statusbar);
c.add(ta);
c.add(ta2);
public static void main(String args[]) {
Test_Stemmer sfc = new Test_Stemmer();
sfc.setVisible(true);
}could you please help me, and tell me what to add or to modify,,
Thank you..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

realahmed8 wrote:
thanks masijade,
i have filter the file chooser for only text files,
but i still don't know how to use FileReader to put text file content to the text area (ta) ..
please tell me how and where to use it..How? -- See the IO Tutorials on Sun for the FileReader (and I assume you know how to call setText and append in the JTextArea).
Where? -- In the actionPerformed method (better would be a separate thread that is triggered through the actionPerformed method, but that is probably beyond you at the moment), of course.
Give it a try.

Similar Messages

  • How to get the contents of jar file?

    Hi
    is there any way we can see the contents of jar file.(Since it is similar to zip file can we unzip it and see the contents)

    You can use:
    this->getClass().getResourceAsStream("/something.txt")
    where 'something.txt' is a file inside your .jar

  • How to get the content in embed swf file in Swf Loader on run time

    How to get the content in embed swf file in Swf Loader on run time
    [Bindable]
    [Embed(source="assets/index.swf")]
       private var SWFSRC:Class;
    <mx:SWFLoader id="_swfloader" source="{SWFSRC}" />

    Hi Flex harUI,
    Throw the error.
    Access of undefined property content

  • How to get the content of the uploaded file.

    Hi Experts,
    I am using a input box to get the path of the file to be uploaded.(I am not using FILE UPLOAD UI Element).Could you please let me know how to get the content of the uploaded file.
    Regards,
    Arun

    >
    ARUN KUMAR.S wrote:
    > Hi Experts,
    >
    > I am using a input box to get the path of the file to be uploaded.(I am not using FILE UPLOAD UI Element).Could you please let me know how to get the content of the uploaded file.
    >
    > Regards,
    > Arun
    You will not be able to use a normal InputField to upload file contents.  This is not allowed by the browser security model. You must use one of the upload specific UI mechanisms - the FileUpload UI element or as of 7.01 ACFUpDownload or FlashIslands.

  • How to get the content of a jTextArea?

    hi everyone
    can some body provide me with some help???
    I want to know how to get the content of a jTextArea
    it may be a String and i want to use that String to make some applications
    I've use this :
    String ch=jTextArea.getSelectedText()
    but i'm not sure it will work and i'm not sure it will take the text writen inside the jTextArea ... please help
    Thanks

    http://forum.java.sun.com/thread.jspa?threadID=778988&tstart=0

  • How to get the complete abap help file

    hi
    how to get the complete abap help file i mean F1 file.
    please provide some me links to download that file.

    Hi Kiran,
       If u want complete help for particular topic ; for that SAP has provided in built Transaction for help.
    Transaction is ABAPDOCU.
    I have certain link which will help u.
    SAP, ABAP interview question and answers
    http://www.geocities.com/sap_interviewquestions/
    IMP Link for All
    http://www.geocities.com/SiliconValley/Campus/6345/abapindx.htm
    Common Links
    http://www.sappoint.com/abap.html
    http://www.sap-img.com/abap-function.htm
    http://www.easymarketplace.de/online-pdfs-q-s.php
    http://help.sap.com/
    http://sapassist.com/groups/groups.asp?v=sap-r3-dev&m=3&y=2004
    http://training.saptechies.com/sap-basis-certification-sample-questions/
    http://www.geocities.com/mpioud/Abap_programs.html
    http://cma.zdnet.com/book/abap/index.htm
    http://www.sapdevelopment.co.uk/
    http://www.sap-img.com/
    http://juliet.stfx.ca/people/fac/infosys/abap.htm
    http://help.sap.com
    http://www.sap-img.com
    http://www.thespot4sap.com
    http://www.sap-basis-abap.com/
    http://www.sapdevelopment.co.uk/
    http://www.sap-img.com/
    http://juliet.stfx.ca/people/fac/infosys/abap.htm
    http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_46c/helpdata/en/d6/0db357494511d182b70000e829fbfe/frameset.htm
    http://www.henrikfrank.dk/abapexamples/SapScript/sapscript.htm
    http://www.sapgenie.com/abap/example_code.htm
    http://www.geocities.com/SiliconValley/Campus/6345/abapindx.htm
    http://help.sap.com/printdocu/core/Print46c/en/Data/Index_en.htm
    http://help.sap.com/saphelp_40b/helpdata/en/4f/991f82446d11d189700000e8322d00/applet.htm
    http://www.sap-img.com/abap-function.htm
    http://www.sapgenie.com/abap/code/abap19.htm
    http://www.sap-img.com/abap/more-than-100-abap-interview-faqs.htm
    http://www.planetsap.com/Tips_and_Tricks.htm
    http://help.sap.com/saphelp_40b/helpdata/ru/d6/0dc169494511d182b70000e829fbfe/applet.htm
    http://www.henrikfrank.dk/abapexamples/SapScript/symbols.htm
    http://www.henrikfrank.dk/abapexamples/index.html
    http://sap.ittoolbox.com/documents/document.asp?i=752
    http://members.aol.com/_ht_a/skarkada/sap/
    http://sappoint.com/abap/
    http://members.tripod.com/abap4/SAP_Functions.html
    http://members.ozemail.com.au/~anmari/sap/index.html
    http://www.planetsap.com/Userexit_List.htm
    http://www.planetsap.com/Tips_and_Tricks.htm
    http://www.kabai.com/abaps/q.htm
    http://www.planetsap.com/Userexit_List.htm
    http://help.sap.com/saphelp_bw21c/helpdata/en/c4/3a8090505211d189550000e829fbbd/frameset.htm
    http://www.sapgenie.com/abap/bapi/example.htm
    http://help.sap.com/saphelp_45b/helpdata/en/65/897415dc4ad111950d0060b03c6b76/content.htm
    http://www.sap-basis-abap.com/index.htm
    http://help.sap.com/saphelp_40b/helpdata/en/fc/eb2c46358411d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_46c/helpdata/en/aa/aeb23789e95378e10000009b38f8cf/frameset.htm
    http://www.geocities.com/ResearchTriangle/1635/system.html
    http://www.sapdesignguild.org/resources/MiniSG/3_Managing/3_Functions_Table_Control.htm
    http://help.sap.com/saphelp_45b/helpdata/en/d1/801bdf454211d189710000e8322d00/content.htm
    http://www.sapfans.com/sapfans/repos/saprep.htm
    http://www.planetsap.com/howdo_a.htm
    http://help.sap.com/saphelp_util464/helpdata/en/69/c2516e4ba111d189750000e8322d00/content.htm
    http://www.sapgenie.com/abap/smartforms_detail.htm
    http://www.sap-img.com/abap.htm
    http://help.sap.com/saphelp_46c/helpdata/en/fc/eb2d67358411d1829f0000e829fbfe/content.htm
    http://www.geocities.com/victorav15/sapr3/abap.html
    http://www.henrikfrank.dk/abapexamples/SapScript/sapscript.htm
    http://abap4.tripod.com/Other_Useful_Tips.html
    http://help.sap.com/saphelp_45b/helpdata/en/cf/21ee2b446011d189700000e8322d00/content.htm
    http://www.sap-basis-abap.com/sapmm.htm
    http://sap.ittoolbox.com/nav/t.asp?t=303&p=448&h1=303&h2=322&h3=448
    http://sapfans.com/
    http://cma.zdnet.com/book/abap/ch03/ch03.htm
    http://help.sap.com/saphelp_40b/helpdata/en/4f/991f82446d11d189700000e8322d00/applet.htm
    http://sappoint.com/abap/
    http://www.henrikfrank.dk/abapuk.html
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/abapindx.htm
    http://www.sapgenie.com/abap/index.htm
    http://www.sap-img.com/abap.htm
    http://www.sapdevelopment.co.uk/tips/tipshome.htm
    http://help.sap.com/printdocu/core/Print46c/en/Data/Index_en.htm
    http://sap.ittoolbox.com/nav/t.asp?t=322&p=322&h1=322
    http://sap.ittoolbox.com/nav/t.asp?t=448&p=448&h1=448
    http://www.thespot4sap.com/
    http://www.kabai.com/abaps/q.htm
    http://www.geocities.com/mpioud/Abap_programs.html
    http://www.sapgenie.com/abap/tips_and_tricks.htm
    http://www.sapassist.com/code/d.asp?whichpage=1&pagesize=10&i=10&a=c&o=&t=&q=&qt=
    Mark Helpfull answrs
    Regards
    Manoj

  • I am thinking of buying a MacBook Air and am wondering how to get the content of my iPad into iTunes.

    I have iTunes on an old pc and am thinking of buying a MacBook Air. I am wondering how to get the content of my iPad on to the Mac as I know that sync only happens in one direction, from pc to device. I assume therefore that when I attach my pad to the new Mac it will sync to an empty iTunes and I will have lost all the content of my pad. I know I can restore purchases, but what about contacts, calendar, photos and music not purchased from apple. I have a fairly recent backup on a pen drive but it is a usb2 device and is formatted for a pc. Any advice would be appreciated.

    Do I copy my media library or from a backup.  I have a backup on my pc and on an external drive. This drive is usb2 and formatted for windows so I can't connect it to a MacBook Air to make the transfer.  Equally I don't think there is a way to connect the 2 computers via a cable ie usb2 one end and usb3 the other.  Will the computers talk to each other via wifi if I enable home share although I think this is only for music which still leaves contacts, mail etc.
    I am sorry to be such an ignoramus but any further help would be appreciated.

  • How 2 get the path of a file

    how 2 get the path of a file Using jsp
    i have tried getPath...but i'm geting the error
    The method getPath(String) is undefined for the type HttpServletRequest
    any idea how 2 get the path of a file

    You need ServletContext#getRealPath().
    API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

  • How 2 get the path of a file Using jsp

    how 2 get the path of a file Using jsp
    i have tried getPath...but i'm geting the error
    The method getPath(String) is undefined for the type HttpServletRequest
    any idea how 2 get the path of a file

    You need ServletContext#getRealPath().
    API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

  • How to get the contents associated with a component.

    How to get the contents associated with a component.
    Like i have 2 buttons and i want to get the contents associated with these button without clicking them i.e without firing the event.
    By Contents i mean, whatever things we get after firing the event,we get some other window and some thing is added to the current page and so on.

    grab all the code inside the actionPerformed(ActionEvent e) method

  • WD ABAP: How to get the contents of selected table lines?

    Hi,
    I'm trying to figure out how to get the contents of table lines back from the UI. I display a table with several lines of data. The user selects some rows. I want to move the contents of the selected rows to another table. I have a context attribute, say DATA, with attributes FIELD1... FIELDn, using a DDIC structure. These are bound to the table UI element and the corresponding table columns. To get the selected rows, I use wd_context->get_selected_elements(). This works, but what I get from this method is references to if_wd_context_element. How do I know which row (row number = ?) this corresponds to? And how do I get the actual data? I want a structure with FIELD1 = value1 FIELD2 = value2 etc. My context attributes FIELD refer to table columns, but I'm looking for the table line...
    Can somebody help me?
    Thanks,
    Ira

    Hi Ira,
    wd_context->get_selected_elements() returns WDR_CONTEXT_ELEMENT_SET which is a table type of IF_WD_CONTEXT_ELEMENT. You can loop through the WDR_CONTEXT_ELEMENT_SET, get into variable say node_elelement which is of type ref to If_Wd_Context_Element. Then you could use the method GET_STATIC_ATTRIBUTES of If_Wd_Context_Element which returns a structure with values of all the attributes in the selected row.
    If you need the row number, while populating the node you could have an additional attribute called rowno and populate it correctly. When you select the data using method GET_STATIC_ATTRIBUTES, you would get the appropriate row number.
    Regards,
    Srini.

  • How to save the contents of a file(not a text file)

    Hi all, I want to save the contents of a file(,png file, not a text file) as a field in a class. Shall I have it as a string or byte array or something?
    I have tried saving a file in a string but there were some problems with loading the file from a different platform. Following is my code.
            String string;
            try {
                StringBuffer sb = new StringBuffer(1024);
                char[] characterArray = new char[1024];
                BufferedReader br = new BufferedReader(new FileReader(file));
                while(br.read(characterArray) != -1){
                    sb.append(String.valueOf(characterArray));
                br.close();
                string= sb.toString();
            } catch (IOException ex) {
                ex.printStackTrace();
            }and I use the following code to recover the string back to a stream, and save that stream back to a time later.
        ByteArrayInputStream bais = new ByteArrayInputStream(map.getBytes());I realized that because this file is not a text file, the string could cause some problems. But anyone could tell me if I should use a byte array or someting? and how?
    Any help would be appreciated!
    Cheers,
    Jing

    You should use a byte array, and the binary streams (InputStream a& OutputStream). Never use Strings and Reader/Writer if you have binary data.
    Kaj

  • How To Fetch the Content of a File from Client's PC?

    In my JSP I have this:
         <input type="file" name="filename">for visitors of the web page to browse their PCs' directories to select a file to upload (when the Submit button is clicked).
    What appears in the text field will be a file name. How do I get both the file name and the content of that file to be saved in the database?

    From http://www.htmlhelp.com/reference/html40/forms/input.html:
    A form that includes a file INPUT must specify METHOD=post and ENCTYPE="multipart/form-data" in the <FORM> tag. CGI libraries such as CGI.pm allow simple handling of such forms.
    Form-based file upload is unsupported by many currently deployed browsers. Authors should provide alternative methods of input where possible.
    The following example allows the user to upload an HTML document for validation:
    <FORM METHOD=post ACTION="/cgi-bin/validate.cgi" ENCTYPE="multipart/form-data">
    <P>Select an HTML document to upload and validate. If your browser does not support form-based file upload, use one of our alternate methods of validation.</P>
    <P><INPUT TYPE=file NAME="html_file" ACCEPT="text/html"></P>
    <P><INPUT TYPE=submit VALUE="Validate it!"></P>
    </FORM>
    Your servlet would then have to process whatever data is put into that parameter. You can look at O'Reilly's servlet utilities, or one of the other other links here:
    http://www.google.com/search?q=java+servlet+file+upload&sourceid=opera&num=0&ie=utf-8&oe=utf-8

  • How to store the contents of a file

    Hi,
    I'm using forms6i and database 10g.
    Through forms if a user selects a filename , and clicks a button or something,
    the contents of the file should be saved in the database.
    The file can be of any type, like .doc,.pdf,.xml,.html etc...
    and the contents filed will be of type varchar
    Please help me do this..
    Thanks

    Do you really want to save the "Content" of a file or the file itself? If you try to save the contents of a .doc or .pdf in a column with a VARCHAR2 datatype, you are going to corrupt the contents of the file since these file types have binary data in them as well as text. I think you would have greater success storing the actual file in a BLOB column.
    Here are a few Oracle Support documents that discuss how to store and retrieve files stored as BLOBs in the database.
    Doc ID: 168277.1 - How to Upload Binary Documents Back to Database BLOB Column from Forms
    Doc ID: 330146.1 - How to write BLOBs Stored Inside the Database Out to Files.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to get the current location text in JTextPane

    hi
    i want to get the current location text in JTextPane ...iam useing
    caretPos = jtpMain.getCaretPosition();
    iam geting the current Locations at the same time i want to read the entery current line
    i used like this
    StartPos=jtpMain.getText();
    but iam geting entry data in JTextPane ... how can get current Locatin data ...
    pls help me

    If I understood your request, what you would like to do is to be able to retrieve Start and End Positions of a given line (a line and NOT the whole content of the JTextPane).
    JTextPane is a graphical component that is bound to a logical document. Documents are structured in elements. What defines an element is up to you to decide if you extend your own document but elements are by default paragraphs (runs of text ended by a carriage return '\n' character). So, I think that what you want to do is to retrieve the Start and End positions of the
    paragraph over which the caret is currently positionned. Then I think you have got to do the following :
    int intStartPos;
    int intEndPos;
    int intCaretPos;
    javax.swing.text.StyledDocument docStyledDoc;
    javax.wing.text.Element eleParagraph;
    intCaretPos = jtpMain.getCaretPosition( );
    //Get a reference to the default styled document bound to the JTextPane component
    docStyledDoc = jtpMain.getStyledDocument( );
    //Get the paragraph element from the document over which the caret is positionned
    eleParagraph = docStyledDoc.getParagraphElement(intCaretPos);
    //Get paragraph's offsets
    intStartPos = eleParagraph.getStartOffset( );
    intEndPos = eleParagraph.getEndOffset( );
    hi
    i want to get the current location text in JTextPane
    ...iam useing
    caretPos = jtpMain.getCaretPosition();
    iam geting the current Locations at the same time i
    want to read the entery current line
    i used like this
    StartPos=jtpMain.getText();
    but iam geting entry data in JTextPane ... how can
    get current Locatin data ...
    pls help me

Maybe you are looking for

  • Unable to update SQL Server thru XI using JDBC Adapter

    Hi, I am trying to update SQL Server. When I run the scenario I get Success status in sxmb_moni, But when I see in SQL server nothing is getting updated. Can anybody let me know where I may be doing wrong? Thanks In Advance. Yaseen.

  • Sales Order CReated with Reference

    Hi, I created a sales order with reference to an existing order. I created delivery based on the new order that was created with reference. HOwever, if i try to get the sales order number of my delivery, the sales order that i am getting is the sales

  • Illustrator CC 2014- Unknown error when saving as PDF with Printer's Marks

    I've been getting an error message (bellow) when I save a ANY of my AI file as PDF with Printer Marls (Trim Marks etc). All fail attempts were files with: No transparencies - No effects - Simple Type (tried outlined and live) - Simple shapes. I tried

  • Problem in customer exit

    Hi all,         I wrote a customer exit and debugged that and the coede was working fine but i am not able to see the result in the query.Can anyone of you suggest what are the possible causes for this.

  • Mac Classic II Startup Problem

    I recently aquired a Macintosh Classic II from a friend, but am experiencing some problems booting it up. When I have the original Classic mouse plugged in and turn on the power, the hard drive starts whirring and making noise, and a bunch of alterna