Displaying a .txt file in a JTextArea

hello everyone, i was wondering if you could help me with a problem i have.
basically, i have to type a word in a TextField that corresponds to a filename. i.e. type in 'results' and that will correspond to a file called 'results.txt'. once i type in this word, i click a button and this will open the file 'results.txt' into a TextArea below.
I have been working on this for several days now. I can figure out how to open the file into the TextArea, but it displays the file in there straight away. I need to make it so that the button has to be pressed first and then displays it.
It also needs to be able to do more than just one file. I have several files in a folder and depending on what i type in the TextField depends on which file is displayed.
I would appreciate ANY help at all on this as I am struggling quite alot.
Thnk you in advance
Troy

correct me if it is a misunderstanding, but why don't you open the file (read in the content of a file in f.e. String text) , then you do a setText(text) ?
in order to find out what was typed in you can choose getText()
so far,
stefan gross

Similar Messages

  • Work around to display large .txt files in Nanos?

    I'd like to read a large .txt file on a Nano...breaking the .txt file into 4k increments isn't feasible.
    Anyone know how to display a large .txt file on a Nano's screen -- from the Notes folder, or, elsewhere?
    Thanks!

    Hmmmm. Not so sure about that one.
    Actually, it might be worth checking through the iPod + iTunesdownloads page to see if there are any useful widgets and whatnot for that there. (There's a few notes-related items showing up there too, which might work better than my suggestions about performing unnatural acts with your lyrics tags.)
    http://www.apple.com/downloads/macosx/ipod_itunes/

  • Displaying doc/txt file contents from portlet

    Hi, Can someone pls give a hint on how to do this:
    One "book" type content created, with a doc file uploaded. The "publisher " for
    this content is set to "sams".
    create a content selector which retrieves only this (content) book correctly.
    create two portlets. one portlet with above content selector inserted, displays
    the publisher name with a hyperlink.
    I want the other portlet to display the contents of the file uploaded, for this
    publisher. I could establish portlet comm. and could display other properties
    of the book such as "author/titile" on the second portlet, but want to know how
    to display the uploaded file contents.
    thanks much,
    -developer

    As far as retriving the contents of an uploaded file...
    If your XML document has been loaded into Content Management as a binary
    property, you have two options:
    a) to directly inline the content into the JSP, do something like this:
    <cm:getProperty id="node" name="binaryPropertyName" failOnError="true"
    isMultiple="false"/>
    (This assumes node holds a reference to the Content Management Node
    object (perhaps retrieved via a <cm:getNode> tag)
    b) to retrieve the value into a script variable for more processing, do
    something like this:
    <%
    Property bodyProp= (Property)node.getProperty("binaryPropertyName");
    InputStream in= node.getPropertyBytes( bodyProp.getId() );
    // dont forget to close the InputStream
    String result=null;
    InputStreamReader reader= new InputStreamReader(in);
    StringBuffer streamContents= new StringBuffer();
    char[] data= new char[8192];
    int charsRead;
    while ((charsRead = reader.read(data)) > 0 )
    streamContents.append(data, 0, charsRead);
    result= streamContents.toString();
    %>
    -Steve
    "portal developer" <[email protected]> wrote in message
    news:40ae343d$[email protected]..
    >
    Hi, Can someone pls give a hint on how to do this:
    One "book" type content created, with a doc file uploaded. The "publisher" for
    this content is set to "sams".
    create a content selector which retrieves only this (content) bookcorrectly.
    >
    create two portlets. one portlet with above content selector inserted,displays
    the publisher name with a hyperlink.
    I want the other portlet to display the contents of the file uploaded,for this
    publisher. I could establish portlet comm. and could display otherproperties
    of the book such as "author/titile" on the second portlet, but want toknow how
    to display the uploaded file contents.
    thanks much,
    -developer

  • How to display a .txt file?

    i would like to ask if JAVA can open and display a text file by issuing a command from my application
    is it possible to do it without using a JEditorPane?
    something else too, how can i set the background for my application to be a .jpg image?
    i searched and realised there is no such method as
    setBackground(String url)

    Try this... Note you need to add adequate exception trapping and detect special cases like the file being larger than the allocatable size of a character array (in which case you can't convert the file to a string and will need to 'display' the file in sections)...
    import java.io.*;
    public class LoadFile {
      public static String fileToString(File file) throws IOException {
        char[] fileContents = new char[(int) file.length()];
        FileReader fr = new FileReader(file);
        if(fr.read(fileContents) != fileContents.length) {
          System.err.println("There was a problem reading the file contents");
          return null;
        else return new String(fileContents);
      public static void main(String[] args) throws IOException {
        if(args.length != 1) System.err.println("Usage:\n\tjava LoadFile <filename>");
        else {
          File f = new File(args[0]);
          try {
            String s = fileToString(f);
            System.out.println(s);
          } catch(IOException e) {
            System.err.println("Whoops");
    }Hope that helps...

  • Displaying a .txt file in a TextArea...

    hello everyone, i was wondering if you could help me with a problem i have.
    basically, i have to type a word in a TextField that corresponds to a filename. i.e. type in 'results' and that will correspond to a file called 'results.txt'. once i type in this word, i click a button and this will open the file 'results.txt' into a TextArea below.
    I have been working on this for several days now. I can figure out how to open the file into the TextArea, but it displays the file in there straight away. I need to make it so that the button has to be pressed first and then displays it.
    It also needs to be able to do more than just one file. I have several files in a folder and depending on what i type in the TextField depends on which file is displayed.
    I would appreciate ANY help at all on this as I am struggling quite alot.
    Thnk you in advance
    Troy

    below is what i have so far, but it has one error. Could u help me with that?
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    public class NorthPanel extends JPanel
    JTextArea instruct;
    String str;
    BufferedReader br;
    public NorthPanel()
    setBackground(Color.white);
    instruct = new JTextArea(5,60);
    instruct.setLayout(new FlowLayout(FlowLayout.CENTER));
    instruct.setBorder(BorderFactory.createTitledBorder("Java Work"));
    instruct.setLineWrap(true);
    instruct.setWrapStyleWord(true);
    instruct.setEditable(false);
    readFileIntoTextArea();
    add(instruct);
    private void readFileIntoTextArea()
    try {
    File f = new File("readme.txt");
    br = new BufferedReader (new FileReader(f));
    while ((str = br.readLine()) != null)
    instruct.append(str);
    }

  • Attached txt file is displayed with sapoffice intead of notepad

    Hi,
    i´ve developed a bsp page that uploads files using fm SO_DOCUMENT_INSERT_API1.
    When i try to display a txt file uploaded as above explained (with transaction FB03) the document is displayed with sapoffice and not with notepad as i expected.
    Why is this hapenning?
    What do i have to do so that a txt file is opened with notepad?
    i´m able to upload a pdf and display it afterwards in fb03  with acrobat reader.
    i´m able to upload a doc and display it afterwards in fb03  with msword.
    but with a txt file it does not work.
    Best regards.
    Edited by: Pablo Casamayor on Nov 19, 2011 12:02 PM

    You should be doing something like this to open a text file in Notepad:
    Message Edited by smercurio_fc on 09-12-2007 01:07 PM
    Attachments:
    Example_BD.png ‏2 KB

  • Reading a text File into a JTextArea

    I know this is really basic question, but what is the best and/or simplest way to read text from a .txt file into a JTextArea? I'm new to Java and any help anyone can provide would be greatly appreciated.

    it should be in quotes only if it is a string repersentation of a String class.
    FileReader reader = new FileReader("readme.txt");
    quotes are not needed if you write it this way
    String filename = "readme.txt";
    FileReader reader = new FileReader(filename);
    ...remember that String is a class and not a data type, it is also a special case in java where the class can act like a datatype in declarations.
    I don't think anything else can behave like this in java
    String text = "sometext";
    "sometext".equals(text);
    this returns true.

  • Output Not Appearing in Exported .TXT File

    Hi
    I am using Crystal Reports XI R2, using Universe as a Data source, and Business Objects XI Release  2.Oracle 10G as a Datasource with Universe.
    I am getting Correct Data, in Crystal  Report Viewer, But if i am making attempt to Export the Data to a .TXT File, it is not displaying tha Data as in Crystal Report Viewer.
    1) In my Case we are Using Page Number Reset Option, which is working fine in Crystal Reports Viewer, but in .TXT file output, Page Number is not reseted.
    2) We are Using Group Headers which has Text Objects and Formula Field,  the Group Header Displays for Each Group in Viewer, but same is not displayed in .TXT File output.
    3) For Very First Group, In Viewer it Displaying Page No as 1,1,2,3.....(which is not Correct, it should be 1,2,3....), but in .TXT file Output, it Displays right One as 1,2,3......
    But If iam Exporting the Report to an PDF File, it Displays Eactly as what is in viewer.
    So Kindly Help me on this Issue.
    Thanks
    M.Mukesh
    Edited by: m.mukesh on Dec 9, 2010 9:49 PM
    Edited by: m.mukesh on Dec 9, 2010 9:50 PM

    Moved to BOE Admin forum

  • Opening an *.txt file in oracle forms 4.5

    I am facing this problem I want to call an text file from a certain location and display the same when an user hits a particular button which has to be done in Oracle Forms 4.5.
    Could u pls help me

    If you want to display the *.txt file use ole object to do that and if you want to read the data from the text file and display in the text field then use textio package.
    Hope this helps you.
    Regards
    Gaurav

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

  • Want to display a space after last field in the output txt file

    hi
    I want to display a space after last field in the output txt file which is generaed by my program on utility server the last field lengyt we have defined is four and in database it is of three characters and requirement is to disppaly the last fourth field as space in the output file w hich is not shown as the txt file automatically gets closed at the third place as it is the last field in the record and ind atabase records are of therss char only but user wants to display this fourth position in the notepad output file as space ( which is last field in the output file)
    eg
    name house  street country
    record output coming in file
    ram   h3      street3  thn      now this thn which is last field the notepad get closed at thn only
    i want to display one space in last field for the whole of output file
    ie ram      h3   street3  thn(space)
        sham   h4  street4   sgp(space)  so on......
    we need to show this space in the output file as blank
    regards
    Arora

    hi Atish
    i am using
    loop at gt_sagadr_outtab into wa_sagadr_outtab
    move wa_sagadr_outtab-country to wa_sagadr_text+223(226).
    endloop
    in this last field ie country i need to display the last 226 as blank as only country key is two char in database so the last space is not shown
    i am not unsing the fM as tolb by  you
    and afterwards
    i am usning
    Concatenate 'Sagadr_' sy-datum sy-uzeit '.dat' into gv_filename_sagadr.
    CALL FUNCTION 'FILE_GET_NAME'
      EXPORTING
      CLIENT                        = SY-MANDT
        LOGICAL_FILENAME              = gc_lfile
        OPERATING_SYSTEM              = SY-OPSYS
        PARAMETER_1                   = gc_param1
        PARAMETER_2                   = gc_send
        PARAMETER_3                   = gv_filename_sagadr
      USE_PRESENTATION_SERVER       = ' '
      WITH_FILE_EXTENSION           = ' '
      USE_BUFFER                    = ' '
      ELEMINATE_BLANKS              = 'X'
      IMPORTING
      EMERGENCY_FLAG                =
      FILE_FORMAT                   =
        FILE_NAME                     =  gv_filepath_sagadr
    EXCEPTIONS
      FILE_NOT_FOUND                = 1
      OTHERS                        = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    and lastly
    open dataset gv_filepath_sagadr for output in text mode encoding default.
        if sy-subrc eq 0.
         loop at gt_sagadr_text into wa_sagadr_text.
         transfer wa_sagadr_text to gv_filepath_sagadr.
         endloop.
        endif.
       close dataset gv_filepath_sagadr.
        if sy-subrc = 0.
        message S002 with gv_filepath_sagadr. "Files & created on Application server
        endif.
    SO NOT SURE WHERE TO USE THE CODE AND HOW

  • Read numbers from a .txt file and display them in a graph

    How can I get Labview 7 to read from a txt. file containing a lot of
    coloumns with different datas? There`s only two of the coloumns that are
    interesting to me, the first, that contains the time of the measuring, and
    one in the middle, that contains the measured temperatures. I want Labview
    to read this datas and display them graphicly.
    Thanks from Stale

    Here's one way.
    You can also use the help-> find examples and search for "text".
    2006 Ultimate LabVIEW G-eek.
    Attachments:
    Graph.vi ‏21 KB

  • How to display Japanese fonts in a .txt file i received?

    I received an email attachment that is a .txt file.
    Some of it is in Japanese and some is in English.
    The Japanese text turns out to look like gibberish.... like this...
    Media Start Media End Duration Log Note
    01:17:12;18 01:17:20;26 00:00:08;09 DZÇÍÇÁÇÃÉCÉìÉåÉbÉgÇÇøÇÂÇ¡Ç∆âÒǡǃÇ≥ÅAÇ¢ÇÎÇÒÇ»É]Å[ÉìÇ÷ǢǡǃǛǃÇsÇÖÇíÇíÇÅÇâÇéÇ ÷LJǡÇ∆ãflÇ≠çsǡǃÇ≥ÅAÉwÉäÇÃñ≥ë éûä‘Çè≠Ç»Ç≠Ç∑ÇÈÅB
    01:17:25;21 01:17:30;21 00:00:05;01 â¥ÇÁÇ©ÇÁ3ÉÅÅ[É^Å[ÇÃÇ∆DZÇÎÇ≈äCÇ™ÉAÉâÉCÉîDžǻǡÇΩÇÊÅI
    01:17:32;10 01:17:36;20 00:00:04;11 ÉwÉäǙdžÇÈÅBëDǙdžÇÈÅBå„âΩÇ™ó~ǵǢÅH
    If i send this cut/paste back to the person who emailed it to me, they say it is displaying fine in Japanese.
    I have no idea how to make this text show up in Japanese.
    Thanks for any help.
    Brian

    You might try giving the file a ".txt" extension. Then drag it on top of your Safari icon in the dock, which should open it with Safari. Then, under "View", select a Japanese "Text Encoding". My guess is that this is Shift-JIS.
    I am assuming you have not removed Japanese fonts from your system.

  • How to display a large file in JTextArea

    i am displaying a large file(a multi MB) in a JTextArea, it is showing java.lang.outofmemoryerror
    are there any solutions for this problem or is there any better way other than JTextArea ???

    thanks for replying but its all abt Tables
    i am new to java
    i asked how to display a large Text file in a JTextAreathanx
    --santosh                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Find and copy files by file name

    Hey Gang, I sure hope you guys can help me out. I'm looking for a piece of software that can read a txt file or spreadsheet to find specific files and copy them from one place to another. In other words, I have a folder with 1000 files in numerical o

  • HT201301 i can't find the file sharing section? why is that?

    i can't find the file sharing section? why is that? it's not shown on my iTunes. . .

  • Newbie question on versions

    I'm just beginning my 30 day freebie and expect to ask for help and advice from time to time. This is a very knowledgeable and helpful group (and an important sales resource to Apple, Mr. Schorr). I think I understand the Aperture concepts of Digital

  • WEBDYNPRO FOR ABAP ALV单元格的颜色问题

    WEBDYNPRO FOR ABAP 的 ALV 的某一个字段的单元格,现在需要把单元格的边框的颜色,改成红色,请问大家有做过的吗?

  • Error: f14627469cba51.pdf file is too large for attachment

    Hi, Recently we migrated lot of crystal reports from BO XI R2 environment to BO 3.1 SP2 FP 2.5 environment, these crystal reports are integrated with the application. Input parameters are given through the application using the Open Document URL and