Set text of jtextArea to a text file

I have tried everything in trying to let the user select a text file using jfilechooser and then set the text of a jtextArea as the text file. Nothing has worked so far, so all I have right here is the basic functionality of choosing the file.
If someone could show me a good way to read the whole text file and put that text into a jtextArea, I would really appreciate it.
Since nothing has worked all I have is this:
JFileChooser chooser = new JFileChooser();
     int returnVal = chooser.showOpenDialog(this);
     String getFile = chooser.getSelectedFile().getPath();

... followed by theJTextArea.read(new FileReader(getFile), null);

Similar Messages

  • How do you read data from a text file into a JTextArea?

    I'm working on a blogging program and I need to add data from a text file named messages.txt into a JTextArea named messages. How do I go about doing this?

    Student_Coder wrote:
    1) Read the file messages.txt into a String
    2) Initialize messages with the String as the textSwing text components are designed to use Unix-style linefeeds (\n) as line separators. If the text file happens to use a different style, like DOS's carriage-return+linefeed (\r\n), it needs to be converted. The read() method does that, and it saves the info about the line separator style in the Document so the write() method can re-convert it.
    lethalwire wrote:
    They have 2 different ways of importing documents in this link:
    http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
    Neither of those methods applies to JTextAreas.

  • Set a timeout for "read from text file"

    I Need to read from a text file on a remote pc and use the read from text file function to do this. It wotks but sometimes this pc is down causing long wait times in my vi.
    Is there a way to set a timeout for the read from text file function, or is there an other solution?
    Thank you

    You could check that the path is valid first before you attempt to read the file.  hen put the file read in a True-False case structure based on the results of the check.  You can use the function "Check if File or Folder Exists"  It checks whether a file or folder exists on disk at a specified path. This VI works with standard files and folders as well as files in LLB files.   The function is found in the File I/O --> Advanced File Functions palette.
    Tom

  • File adapter-How to set line break in text file-split record into two lines

    Dear Guru's,
    I have to solve following problem with XML (with mulitiple records) to TEXT file scenario using file adapter. I have to output for ever ONE data record in XML always two identical lines in text file. Second line should have a little bit different mapping in few fields like date,... So I did duplicate fileds in my output structure in mapping and need to know how to set line break in the middle and see half of structure in first line and next structure half in second line
    My output structure in mapping is:
    CASHFLOW
    - INTERFACE
    - GESELLSCHAFT
    - ANWENDUNG
    - PRODUKT
    - VERTRAG
    - BETRAG
    - WAEHRUNG
    - DIRECTION
    - BEWEGUNGSTYP
    - FAELLIGKEIT
    - ZINSFESTSTELLUNG
    - ZAHLUNGSTAG
    - RENDITE
    - INTERFACE2
    - GESELLSCHAFT2
    - ANWENDUNG2
    - PRODUKT2
    - VERTRAG2
    - BETRAG2
    - WAEHRUNG2
    - DIRECTION2
    - BEWEGUNGSTYP2
    - FAELLIGKEIT2
    - ZINSFESTSTELLUNG2
    - ZAHLUNGSTAG2
    - RENDITE2
    Question is how can I set on receiving file adapter in Content Conversion Parameters that fields from first structure half INTERFACE...RENDITE should be outputed in one line and fields from second half of structure INTERFACE2...RENDITE2 should start on second line in final text file.
    I'm getting at the moment one line only and I need to know how can set line break so that second line starting with INTERFACE2(CA)...RENDITE2 will start in new line.
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000",CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    This should be final output:
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000"
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    My file adapter settings:
    RecordsetStructure=CASHFLOW
    CASHFLOW.fieldNames=INTERFACE,GESELLSCHAFT,ANWENDUNG,PRODUKT,VERTRAG,BETRAG,WAEHRUNG,DIRECTION,BEWEGUNGSTYP,FAELLIGKEIT,ZINSFESTSTELLUNG,ZAHLUNGSTAG,RENDITE
    CASHFLOW.fieldSeparator=,
    CASHFLOW.endSeparator='nl'
    CASHFLOW.fieldNames=INTERFACE2,GESELLSCHAFT2,ANWENDUNG2,PRODUKT2,VERTRAG2,BETRAG2,WAEHRUNG2,DIRECTION2,BEWEGUNGSTYP2,FAELLIGKEIT2,ZINSFESTSTELLUNG2,ZAHLUNGSTAG2,RENDITE2
    CASHFLOW.fieldSeparator=,
    It wont help if I add two identical structures in mapping because in output i would see for multiple entries section with first lines only and after that section with second lines only. And CASHFLOW is one part of more complex mapping ...
    (This is final output structure RecordsetStructure=HEADER,CASHFLOW,CONDITION,REFERENCE,CONTRACT - more sections with different data and all these should have duplicate lines at the end)
    Thanks a lot for any help
    Cheers
    Marian
    Edited by: Marian  Luscon on Jul 14, 2009 11:44 AM

    Hi Ivan,
    right, I did test just for sure.
    Putting constant 'nl' into field CASHFLOW-INTERFACE1 didnt help - still getting one line instead two lines.
    CA ,"0100" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,2 ,12 ,2009-01-28 ,2009-01-27 ,2009-01-28 ,"0.0000000" ,'nl' ,"GTP1" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,1 ,10 ,2009-01-27 ,2009-01-27 ,2009-01-27 ,"0.0000000"
    So there is still question. Is there any way (mapping,...) how to output always 2 lines in text file for one record in XML. It always does 1 record in mapping structure = 1 line but we need 2 lines ...
    Example:
    Input: 4 records in XML
    Output: 8 lines in final text file ...
    Thanks to you all guys
    Marian

  • Dynamic Distribution Group set conditions by importing text file?

    Exchange 2010 SP2.
    I created a dynamic distribution group via the EMC.  We have populated AD with ExtenstionAttribute1 and ExtensionAttribute2.  I have created the ddg with custom attribute1 value = employee.  What I need to do now is  populate custom attribute
    2 = 00-0001, 00-0002, and so on.  There are about 300 of these numbers I need to add.  I have them in a text file or csv file.  Instead of adding them one by one in the EMC, is there a way to import them via powershell to the existing ddg? 
    The ddg is called All Management Employees.

    If they go from 00-0001 to 00-0300, you could just add them as follows:
    Set-DynamicDistributionGroup <group name> -RecipientFilter "(CustomAttribute1 -eq 'employee') -and (CustomAttribute2 -like '00-0*')"
    However, if you have additional items like this (such as 00-0350, etc), you may need to use the following:
    Set-DynamicDistributionGroup <group name> -RecipientFilter "(CustomAttribute1 -eq 'employee') -and ((CustomAttribute2 -like '00-00*') -or (CustomAttribute2 -like '00-01*') -or (CustomAttribute2 -like '00-02*') -or (CustomAttribute2 -eq '00-00300')"
    Now, if your numbering isn't sequential and it can't be, you would need to add them individually - which may make your search filter unusable, in which case, you may need to create several dynamic groups and add them to a parent group.

  • Setting Font for converting multiple text files into PDF using VB 6.0

    Dear All,
    Am converting multiple text files into PDF using VB6.0. Currently, am unable to control the font face and size for the generated files. Below is the procedure am using for each file;
    Public Sub proc_convert_to_PDF(srcFilename As String, destFilename As String)
    Dim p_AcroApp As CAcroApp
    Dim p_VDoc As CAcroAVDoc
    Dim p_DDoc As CAcroPDDoc
    Dim IsOk As Boolean
    Set p_AcroApp = CreateObject("AcroExch.App")
    Set p_VDoc = CreateObject("AcroExch.AVDoc")
    Call p_VDoc.Open(srcFilename, "")
    Set p_VDoc = p_AcroApp.GetActiveDoc
    If p_VDoc.IsValid Then
    Set p_DDoc = p_VDoc.GetPDDoc
    ' Fill in pdf properties.
    p_DDoc.SetInfo "Title", Format(Date, "dd-mm-yyy")
    p_DDoc.SetInfo "Subject", srcFilename
    If p_DDoc.Save(1 Or 4 Or 32, destFilename) <> True Then
    MsgBox "Failed to save " & srcFilename
    End If
    p_DDoc.Close
    End If
    'Close the PDF
    p_VDoc.Close True
    p_AcroApp.Exit
    'Clear Variables
    Set p_DDoc = Nothing
    Set p_VDoc = Nothing
    Set p_AcroApp = Nothing
    End Sub
    What I need;
    1) to be able to set the font face of the destination file ( destFilename)
    2) to be able to set the font size of the destination file ( destFilename)
    Am using Adobe Acrobat 7.0 Type Library
    Kindly Help.
    Thanks in advance

    We didn't say it doesn't work. We said it isn't supported.
    There are a number of other ways to make a PDF. The one which would
    give the most control is if your application directly printed to GDI,
    controlling the font directly. This could print to Adobe PDF.
    You could look for an application that gives control of font for
    printing.
    You could use a text-to-PostScript system and distill the result. You
    could even look for a non-Adobe text-to-PDF.
    Working in the unsupported and dangerous world you chose, the font
    size for text conversion is set (and this is very bad design from
    Adobe) in the settings for Create PDF > From Web Page. There is no API
    to this.
    Aandi Inston

  • 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.

  • How can I assign a text file to JTextArea component??

    Hi every body, does any boody has a code for read a text file and show this text in a JTextArea??? I'm trying with a FileReader but the text doesn't appear well.
    Thanks in advance.
    Juan

    String s = "";
    BufferedReader reader =
                             new BufferedReader(new FileReader(path));
                        String temp = reader.readLine();
                        s += temp + "\n";
                        while (temp != null)
                             temp = reader.readLine();
                             if (temp != null)
                                  s += temp + "\n";
                        reader.close();
    textArea.setText(s);

  • Could not parse the file contents as a data set. There were too many variable names in the first line of the text file.

    Could not parse the file contents as a data set. There were too many variable names in the first line of the text file.

    What are the Variables settings, what is the text file’s content, …?

  • (Administration - Marketing - Import), you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in

    Administration - Marketing -> Import, you can set a parameter value "Import mode" for what to do in case of duplication as "update existing records", "Import new records". The final report of this import is presented as a text file that can be viewed in Business Administration - Marketing -> Import -> Exceptions. Whatever the exception, including duplication import occurs during import and recorded in a text file.   What are the fields that determine the duplicity? How I can I can change those?

    You will be returned anything that is in the option's value parameter. What is displayed in the dropdown and what is put in the value attribute do NOT need to be the same, so maybe you should start there.

  • Why does saving text from a jtextarea to a text file result in....?

    one long string that includes square blocks when the new line should be?
    Why can't I read normal text from a text file. It looks like i have to save it first for it to be read.
    Also why is it that my application succesfully reads and displays the contents of a text file that i just saved but when i manually open that file I don't see it. All i can see is what the text that i manually entered into the text file.
    I use a buffered reader so wondered if there was some caching but have no idea.

    one long string that includes square blocks when the new line should be? If you use something like:
    write(textArea.getText())
    then "\n" will be written to the file as a newline string, but on a Windows platform the newline string is "\r\n".
    You should be using the read(...) and write(...) methods of the JTextArea and the newline string will be handled correctly.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    class TextAreaLoad
         public static void main(String a[])
              final JTextArea edit = new JTextArea(5, 40);
              JButton read = new JButton("Read some.txt");
              read.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        try
                             FileReader reader = new FileReader( "some.txt" );
                             BufferedReader br = new BufferedReader(reader);
                             edit.read( br, null );
                             br.close();
                             edit.requestFocus();
                        catch(Exception e2) { System.out.println(e2); }
              JButton write = new JButton("Write some.txt");
              write.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        try
                             FileWriter writer = new FileWriter( "some.txt" );
                             BufferedWriter bw = new BufferedWriter( writer );
                             edit.write( bw );
                             bw.close();
                             edit.setText("");
                             edit.requestFocus();
                        catch(Exception e2) {}
              JFrame frame = new JFrame("TextArea Load");
              frame.getContentPane().add( new JScrollPane(edit), BorderLayout.NORTH );
              frame.getContentPane().add(read, BorderLayout.WEST);
              frame.getContentPane().add(write, BorderLayout.EAST);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Reading in Latin Extended-A character set from a text file

    Hello all,
    I am writing a small program that reads in a text file containing special characters (beyond the ASCII char set) and converting it into "regular" characters. For example I would read in a uaccent and replace it with a u.
    Now I realize that Unicode support is built into Java from ground up but it goes only so far, you actually have to have the relevant character set to read it. My code is as follows:
    InputStreamReader inStreamReader = new InputStreamReader(new FileInputStream("input.txt"), "ISO-8859-1");
    BufferedReader bufferedReader = new BufferedReader(inStreamReader);
    String line = null;
    StringBuffer buff = new StringBuffer();
    while((line = bufferedReader.readLine()) != null) {
    char[] charArray = line.toCharArray();
    for(int i = 0; i < charArray.length; i++) {
    int x = (int)charArray;
    switch(x) {
    case 224: // this is agrave .. we need to replace it with a
    buff.append('a');
    break;
    case 230: // this is aelig .. we need to replace it with ae
    buff.append("ae");
    break;
    ///////// and so on
    Since I am reading in as ISO-8859-1, this works up to unicode 255. For the rest of the characters, apparently I need a Latin Extended-A and Latin Extended-B character set. How can I get that installed on my Windows OS machine? I am using jdk 1.4.1 on Windows XP. Any help is appreciated.
    Thanks,
    -vk4t

    vkat wrote:
    Since I am reading in as ISO-8859-1, this works up to unicode 255. For the rest of the characters, apparently I need a Latin Extended-A and Latin Extended-B character set. How can I get that installed on my Windows OS machine? I am using jdk 1.4.1 on Windows XP. Any help is appreciated.If your file has characters outside of 8859-1's range (0 - 255), then it isn't ISO-8859-1 encoded. You need to know what encoding was used to store the file. It sounds like you it actually may be Unicode text, in which case you need to know which encoding (UTF8, UTF16, etc) was used.

  • When I send inline photos, recipients receive jumbled text file. What setting do I need to change?

    When I send inline (embedded) photos, along with text; my recipients say they only receive a jumbled text file. Is there a setting within TB I can change to correct this? See below:
    Message-Id: <iPTA1p0151ZQlML01PTCq2>
    Old-Message-Id: <[email protected]>
    X-CT-Class: Clean
    X-CT-Score: 0.00
    X-CT-RefID: str=0001.0A020202.54BEE450.020A,ss=1,re=0.001,fgs=0
    X-CT-Spam: 0
    X-Authority-Analysis: v=2.0 cv=ZM0JbwHb c=1 sm=1
    a=H9ApUXk15iS5yeOMHhxLeQ==:17 a=XD52yEjQpfAA:10 a=IkcTkHD0fZMA:10
    a=8LaAqv5HAAAA:8 a=YNv0rlydsVwA:10 a=ZtyhI0BCAAAA:8
    a=6SNPnC5c-BsZy3R9Qp8A:9
    a=QEXdDO2ut3YA:10 a=_W_S_7VecoQA:10 a=dEDsMZyNvvyTj/aoxoOu+Q==:117
    X-CM-Score: 0.00
    Received: from [192.168.11.108] (really [173.216.226.221])
    by txofep02.suddenlink.net
    (InterMail vM.8.04.01.08 201-2343-100-153-20121108) with ESMTP
    id
    <20150120232710.SKRU21350.txofep02.suddenlink.net@[192.168.11.108]>;
    Tue, 20 Jan 2015 17:27:10 -0600
    Message-ID: <[email protected]>
    Date: Tue, 20 Jan 2015 17:27:03 -0600
    From: "Ron F." <[email protected]>
    User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101
    Thunderbird/31.4.0
    MIME-Version: 1.0
    To: undisclosed-recipients:;
    Subject: Have A Great Day!!!!
    References:
    <[email protected]m>
    In-Reply-To:
    <[email protected]m>
    Content-Type: text/html; charset=utf-8
    Content-Transfer-Encoding: 8bit
    X-Cloudmark-Analysis: v=2.1 cv=fccjyigF c=1 sm=0 tr=0 a=2fDfVs0_6TAA:10
    a=IkcTkHD0fZMA:10 a=8LaAqv5HAAAA:8 a=YNv0rlydsVwA:10 a=ZtyhI0BCAAAA:8
    a=6SNPnC5c-BsZy3R9Qp8A:9 a=8YrWDim6EiZkUi7e:21 a=QEXdDO2ut3YA:10
    a=_W_S_7VecoQA:10
    X-Antivirus: AVG for E-mail 2014.0.4800 [4257/8962]
    X-AVG-ID: ID39D19FBF-2644597C
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <div>
    <div>
    <div>
    <div style="background:white"><b><span
    style="font-size:13.5pt"><img moz-do-not-send="true"
    src="http://j.b5z.net/i/u/7000617/i/a.jpg?n=34148"
    height="492" width="658"></span></b><span
    style="color:black"></span></div>
    </div>
    </div>
    </div>
    <div>
    <div>
    <div>
    <div style="background:white"><span
    style="font-size:10pt"></span><span
    style="color:black"></span>Â <b><span
    style="font-size:13.5pt"><img moz-do-not-send="true"

    this forum just scrambles posts like yours... could you email me one of your problem email to unicorn dot consulting at gmail dot com.... Please put a subject in that will give me a clue.

  • How to redirect "-verbose" Java Runtime Parameter setting to text file

    Simple question: I am adding a "-verbose" Java Runtime Parameter in the Java Applet Runtime Settings of the Java Control Panel. When I run my applet, a Windows console opens which outputs all the method calls, classes, and jar file information. How can I redirect this output to a text file?
    I noticed Xloggc:+filename+ but there does not seem to be an equivalent for redirecting the '-verbose' output to a file.
    Thanks!
    Edited by: zillius on Dec 14, 2007 1:47 PM

    Thank you both for the reply, but unfortunately that is not quite what I am looking for. The console Window I am talking about is a DOS console screen, not the Java Console
    What I am really after here is the ability to redirect a thread dump of a running applet to a text file. When the applet is active, and the "-verbose" parameter is set in the Java Runtime Parameters", I can see all the classes, methods etc. being loaded in the DOS window. Hitting Ctrl-Break at that point will produce a thread dump in the DOS console screen. I would like to be able to redirect THAT output to a text file. It is not in the Java Console. To me it looks like tracing and logging are only for the Java Console, no?
    Thanks again for your help.
    Edited by: zillius on Dec 19, 2007 7:17 AM

  • Text file will only print one set of input and puts in end for name.

    Okay, I have this more or less straightened out. Only thing is, it creates the text file, and will only enter one set of data. It will not print the other students information to the text file. The other thing it does is puts in the student name as end. I think that has something to do with the fact that I need to compare the student name field (SName) to end, so the program can be ended. Anyone have some ideas? I have been working on this for almost 2 weeks, and am about ready to throw the computer off a cliff..
    Thanks.
    import java.io.*;
    import java.lang.*;
    import java.text.*;
    import java.util.*;
    import java.text.DecimalFormat;
    import java.lang.Comparable;
    class my_main
         public static void main (String [] args) throws IOException
         gradebook pt= new gradebook();
         pt.compare();
    class gradebook
         char LG;
         double gr1;
         double gr2;
         double gr3;
         double avg;
         String SName;
         String IDNO;
         String nameupper;
         int compareTo;
         void compare()throws IOException
         FileWriter file= new FileWriter("Grades.txt");
         BufferedWriter bw= new BufferedWriter(file);
         PrintWriter outfile= new PrintWriter(bw);
    BufferedReader stdin;
    stdin= new BufferedReader (new InputStreamReader (System.in));
    System.out.println("Enter Student Name or End to Quit: ");
    SName= stdin.readLine();
    nameupper= SName.toUpperCase();
    DecimalFormat fmt= new DecimalFormat ("##.##");
    outfile.println ("");
    outfile.println (" STUDENT GRADES ");
    outfile.println ("");
    outfile.println ("SName ID # GRADE 1 GRADE 2 GRADE 3 AVERAGE LETTER");
    while(nameupper.compareTo("END")!=0)
    if (nameupper.equalsIgnoreCase("END"))
    break;
         System.out.print ("Student ID: ");
         IDNO= stdin.readLine();
         System.out.print ("Grade One: ");
         gr1= Double.parseDouble(stdin.readLine());
         System.out.print ("Grade Two: ");
         gr2= Double.parseDouble(stdin.readLine());
         System.out.print ("Grade Three: ");
         gr3=Double.parseDouble(stdin.readLine());
         System.out.println ("");
         avg=(gr1+gr2+gr3)/3.0;
         if (avg >= 90) LG = 'A';
    else if (avg >=80 && avg <90) LG = 'B';
    else if (avg >=70 && avg <80) LG = 'C';
    else if (avg >=60 && avg <70) LG = 'D';
    else LG = 'F';
    System.out.println("Enter Student Name or End to Quit: ");
    SName= stdin.readLine();
    nameupper= SName.toUpperCase();
    outfile.print (""+SName);
    outfile.print (" "+IDNO);
    outfile.print (" "+fmt.format(gr1));
    outfile.print (" "+fmt.format(gr2));
    outfile.print (" "+fmt.format(gr3));
    outfile.print (" "+fmt.format(avg));
    outfile.print (" "+LG);
    outfile.println("");
    outfile.close();
         

    Not 100% sure this is what you're after, but it seems to work OK
    import java.io.*;
    import java.lang.*;
    import java.text.*;
    import java.util.*;
    import java.text.DecimalFormat;
    import java.lang.Comparable;
    class my_main
      public static void main (String [] args) throws IOException
        gradebook pt= new gradebook();
        pt.compare();
    class gradebook
      char LG;
      double gr1;
      double gr2;
      double gr3;
      double avg;
      String SName;
      String IDNO;
      String nameupper;
      int compareTo;
      void compare()throws IOException
        FileWriter file= new FileWriter("Grades.txt");
        BufferedWriter bw= new BufferedWriter(file);
        PrintWriter outfile= new PrintWriter(bw);
        BufferedReader stdin;
        stdin= new BufferedReader (new InputStreamReader (System.in));
        System.out.println("Enter Student Name or End to Quit: ");
        SName= stdin.readLine();
        nameupper= SName.toUpperCase();
        DecimalFormat fmt= new DecimalFormat ("##.##");
        outfile.println ("");
        outfile.println ("STUDENT GRADES ");
        outfile.println ("");
        outfile.println ("SName ID # GRADE 1 GRADE 2 GRADE 3 AVERAGE LETTER");
        while(nameupper.compareTo("END")!=0)
          if (nameupper.equalsIgnoreCase("END"))
          break;
          System.out.print ("Student ID: ");
          IDNO= stdin.readLine();
          System.out.print ("Grade One: ");
          gr1= Double.parseDouble(stdin.readLine());
          System.out.print ("Grade Two: ");
          gr2= Double.parseDouble(stdin.readLine());
          System.out.print ("Grade Three: ");
          gr3=Double.parseDouble(stdin.readLine());
          System.out.println ("");
          avg=(gr1+gr2+gr3)/3.0;
          if (avg >= 90) LG = 'A';
          else if (avg >=80 && avg <90) LG = 'B';
          else if (avg >=70 && avg <80) LG = 'C';
          else if (avg >=60 && avg <70) LG = 'D';
          else LG = 'F';
          outfile.print (SName+" "+IDNO+" "+fmt.format(gr1)+" "+fmt.format(gr2)+
                          " "+fmt.format(gr3)+" "+fmt.format(avg)+" "+LG+"\r\n");
          System.out.println("Enter Student Name or End to Quit: ");
          SName= stdin.readLine();
          nameupper= SName.toUpperCase();
        outfile.close();
    }

Maybe you are looking for

  • Windows recognizes ipod but updater or itunes not

    hey folks i need help pretty bad. i do have 30GB ipod photo. when i plug it in to power suplly it's not getting charged,windows recognaizes it as a removable harddisk but when i open i-tunes it doesn't recognizing at all neither ipod updater. when op

  • How do I download all the songs in my wish list at the same time?

    How do I download all the songs in my wish list at the same time?

  • TrueTime Card and how to interface with dll file!?

    I am trying to interface with a PCI-SG 2U (IRIG) timing card (Used to made by TrueTime, now Symmetricom).  Does anyone have a solution for this card in LV 2009?   If not, can anyone give advice on writing code to interface with .dll file?  I am not

  • About Using Hints in OWB

    Hi ALL I am facing one diffculty about using hints in OWB. Through the mapping configuration, i am trying to use INDEX hint for my table. The generated code is correct, but is a very redundant code. Hint is repeating multiple times in the sub query.

  • New iMac on the way - need reassurance!

    Wow! I just found this forum and I'm dumbfounded. I finally decided to go with an Apple product after reading all of the glowing reviews and references to "life beyond the PC". I have a new iMac 24 on the way and holy c**p, I'm freaked. I read throug