How to work on 2 open text files in one main program

I write to one text file and then I close it. I then open another text file in the same "main" class but I cannot write to this file - I get the following error: "Exception in thread "main" java.util.NoSuchElementException".
Here's the code with the line underlined, at which point the error above gets reported:
import java.io.*;
import java.util.*;
public class TwoFileStudentMarks
public static void main(String[] args) throws IOException
PrintWriter stFile = new PrintWriter (new FileWriter ("stFil.txt"));
Scanner kbd = new Scanner(System.in);
int lineNum = 0;
System.out.println("Type in a name: (ZZZ to stop)");
String name = kbd.nextLine();
while (!name.equalsIgnoreCase("ZZZ"))
stFile.println(name);
lineNum++;
System.out.print("Input next name: (ZZZ to stop)");
name = kbd.nextLine();
stFile.close();
kbd.close();
PrintWriter tstFile = new PrintWriter (new FileWriter ("tstFil.txt"));
kbd = new Scanner(System.in);
for (int j=0; j<lineNum; j++)
for (int i=0; i<3; i++)
System.out.print("For student " + j + " enter test " + i + ": ");
int tst = kbd.nextInt();
tstFile.print(tst+" ");
tstFile.println();
tstFile.close();
kbd.close();
} // end main     
} // end class

Thank You for responding to my question. I am new to the forum. I have posted only ONE question since joining on Novemebr 5th, 2007. So I have a question. What are tags  and how does one include them in a question that one wishes to post to the forum?
Secondly, my experience of Java is only about 10 months. So any advice, tips, replies are greatly appreciated and most welcome, so that I may continue to use this language.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Where are these unix executable files coming from and how do I recover the original text file?

    where are these unix executable files coming from and how do I recover the original text file?

    When you upgraded to Lion did you have AppleWorks installed on your mac?
    Most of the AW documents can be opened by Pages 09 or Numbers 09 with most of the orginal format in tact. (I do not know if previouse verision will work) just open the AW file with both and see which one works best.
    Text Edit will also open most of the AW files as well but will require a lot of work to restore them to their orginal format.
    If you have AW Database documents then they are not supported. 
    These document show up as "exec icons", Kind: Unix Executagle File.
    They also will show up as .cwk file if they are small files. I have a couple that were under 1mb that are shown as " Kind: AppleWorks Document" but will not open.
    The only option to open AW database is to have AW installed on a mac with a pre-Lion OS to recover the file.

  • How come pages won't open PDF files made by Pages?

    How come pages won't open PDF files made by Pages?
    I have files I made with Pages and exported as PDF but I can't open them with pages to edit?
    Also, where are the recent files created by pages located? Can't find those to open either..

    Hi Tom,
    I was delighted when I signed up for Pages. Clunky yes, but it worked. I've been a graphic designer on a Mac for 25 plus years and have logged too many horror stories of "upgrade" wars which cost me massive lost time, data and money forcibly extracted just so I could finish a project.
    When I first used Pages in April of 2012? or there about, I was able to open Word documents exported to .pdf format, emailed to me, which I then dragged into Pages. I could make the changes I needed to make, export as a .pdf, return it back to my client which they could then edit on whatever it was they were using. I'm not a neophyte with this. I've had Original Photoshop as a stand alone, Quark (which locked users out 6 months after I purchased it.) Quark again, Freehand, Pagemaker, Illustrator, Photoshop again, Creative Suite for several upgrades, Acrobat Pro. 2 years ago I lost 6 years of Quicken data and had to and "upgrade" start over. This last go around I  had to "upgrade" my Apple ID - yes I had 2 on purpose, lost my Pandora One and my ability to get into the Tulsa County Library website.
    At this point, I'm retired and feel like what I've paid for in the past should WORK today. I have a 100+ page cookbook in Quark which I was able to export as a .pdf, that I've lost the tags too, Easier to start over. I have artwork that is hundreds of megs in Photoshop. Not the least bit interested in anybody's "cloud".
    Thanks for letting me vent. I'm determined to keep my equipment and software up to date so I can enjoy the skills I've acquired, but I completely cringe at Apple's antics. I truly hate it when I have to respond to some new "tip" or product offer. BooHiss. Happy Turkey Day. Pages is a "turkey" program.
    Best regards, mbd

  • 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 u insert and retrieve text files in any format using forms6i.

    how can u insert and retrieve text files in any format using forms6i.
    can u give me an example of an insert statement, let's assume the file is located in the a:drive.
    and retrieving the files, i would give the user a list of all the files that are in the database, the user would select one, but what command(or piece of code) would open the file in its apppropriate editor.
    e.g .pdf formatted file would open in acrobat.
    any help would be appreciated.
    Thanks
    Hussein Saiger

    the filereference class is for downloading and uploading files.
    if you want to load xml, use the xml class.
    and, if you want to write to an xml file and don't want to use server-side code, wait.

  • Error in opening text file in JSF

    Hello,
    I am developing a Web application using JavaServer Faces Beta Version 1.0 and the Web application needs to open a text file. I used a Java class called by a backingbean class to open the text file.
    The problem is that the system cannot find and read the text file.
    The system shows the following errors.
    Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: javax.faces.el.EvaluationException: java.lang.RuntimeException: Could not
    read text file test.txt: java.io.FileNotFoundException: test.txt (The system cannot find the file specified)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:207)
    root cause
    javax.faces.FacesException: javax.faces.el.EvaluationException: java.lang.RuntimeException: Could not read
    text file test.txt: java.io.FileNotFoundException: test.txt (The system cannot find the file specified)
         com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:83)
         javax.faces.event.ActionEvent.processListener(ActionEvent.java:57)
         javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:974)
         javax.faces.component.UICommand.broadcast(UICommand.java:274)
         javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:217)
         javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:316)
         com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:80)
         com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:171)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:196)
    note The full stack trace of the root cause is available in the Tomcat logs.
    I would like to ask how to open text file in the JSF framework.
    Thank you in advance.
    regards,
    oscar

    This is not a JavaServer Faces related issue. Anytime you try to open disk files in a web application, you need to use absolute pathnames. You have no control over what the current directory of our servlet container is set to.
    If the file you're reading is actually inside your web application (say, "test.txt" is in a subdirectory "files" ), you can get access to an input stream for it, in a portable way, by calling the getResourceAsStream() method on ServletContext. From an event handler, that might look like this:
      ServletContext sc = (ServletContext) FacesContext.getCurrentInstance().
        getExternalContext().getContext();
      InputStream stream = sc.getResourceAsStream("/files/test.txt");Craig McClanahan

  • 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

  • When I open a file in Photoshop CS4, how can I resize My Open Window File?it is stuck on full screen

    When I Open a File in Photoshop CS4, How can I Resize My Open Window File? It is stuck on Full Screen?

    Which operating system are you using?
    On a windows os, usually one can just double click on the title bar in the open dialog.

  • How would you like to open this file?

    I'm using Internet Explorer 7.0.5730.13CO and I'm using Adobe Reader 9.3.2.  We have recently upgraded the browser and reader mentioned.  Now when I open a PDF document within the browser, it asks me how I would like to open the file, i.e. Read-Only or Edit mode.  We certainly can't edit these PDF's, so is there any way to get rid of this prompt and just open the PDF's in Read-Only mode? 
    Thanks

    Hi ,
    As far as I know, This is a default feature. and is not recommended to delete or deactivate this pop up. 
    This is a feature of office and there is a dll called owssupp.dll which is responsible for getting the popup to open.
    You can go to IE tools> addon settings and deactivate the above dll (sharepoint open document class). But if you do so, then the other office office files which are word/excel/pptx etc.. would aslo gets affected and they also wont get the popup.
    Hope this helps.
    Best Regards, Ashok Yadala

  • Open text files & save as worksheets in excel with Automator?

    hi,
    i'm an Automator newbie and i'll admit upfront i don't know apple script. i have a bunch of text files that i'd like to open in excel. the basic actions would be to tell excel to look for 'all documents' and to open as space delimited. then i want to save the files as excel spreadsheets rather than txt files.
    i assume i need to use some combination of applescript and automator to do this, but i don't even know where to start. it seems this is something simple someone might have already written a script/action for. is there a repository of such things anywhere? if not, does anyone want to help me through the process of creating such an action?
    thanks,
    jill
    PB G4 1.5GHz, dual PM G5   Mac OS X (10.4.7)   airport, bluetooth

    jill,
    Here is a solution.
    Create an Automator workflow with the following actions:
    1) Get Specified Finder Items (specify the folder containing your space delimited text files)
    2) Get Folder Contents
    3) Run AppleScript (delete all of the text in the action, click on the link below which will put the AppleScript into Script Editor, select the whole thing, copy it to the Clipboard, paste it into the action)
    click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">on run {input, parameters}
    repeat with aTextFile in input
    set theTextFilePath to aTextFile as string
    tell application "Microsoft Excel"
    open text file filename theTextFilePath data type delimited with space
    set theWorkbook to last workbook
    set thePath to path of last workbook
    set theOriginalWorkbookName to name of last workbook
    set theNewWorkbookName to ((characters 1 through -5 of theOriginalWorkbookName) as string) & ".xls"
    set theNewFilePath to thePath & ":" & theNewWorkbookName
    save workbook as theWorkbook filename theNewFilePath file format workbook normal file format
    close theWorkbook saving no
    end tell
    end repeat
    return input
    end run</pre>
    I am assuming that the text files are the only files in the folder. If they are not then some further filtering will be required likely through inserting a Filter Finder Items action after step 2).
    PowerBook 12"   Mac OS X (10.4.7)  

  • How can I open many files in one window?

    how can I open many files in one window?

    Well when i do that, the fonts kinda stays whereas the size of the poster shrinks.
    But thanks for the help

  • How to make photoshop cs4 open dng files?

    How to make photoshop cs4 open dng files?

    They are opened by Photoshop through the ACR plug-in you should make sure the ACR 5.7 update is installed for your CS4.
    Adobe - Photoshop : For Macintosh
    Adobe - Photoshop : For Windows

  • How do i open .msi files to download a program?

    How do I open .msi files to download a program?

    .msi appear to be Windows Installer files.
    You need to install Windows to install and run such files.

  • I have a main fillable form.  From this main form the user may need additional forms.  I want to create checkboxes that link to these additional forms.  This part I believe I know how to do (Properties/Actions/Open a File).  What I want to add is a javasc

    I have a main fillable form.  From this main form the user may need additional forms.  I want to create checkboxes that link to these additional forms.  This part I believe I know how to do (Properties/Actions/Open a File).  What I want to add is a javascript to the checkbox that when the new file (or form) opens some of the data (the repetitive data like name, date, etc.) from the main form is placed into the form opened where the same form fields exist.  Is this possible?

    Yes, but then it all has to be done using a script. You can't use the built-in Open A File command.

  • On a certain site when saving a file, Firefox doesn't ask me if I want to save or if I want to open the file with a particular program. How do I change that?

    I want to open certain file types with a program (eg: adobe illustrator) without having to save it first but depending on the website, Firefox does not as me whether I want to save or open with...

    See:
    *http://kb.mozillazine.org/File_types_and_download_actions
    *https://support.mozilla.com/kb/Managing+file+types

Maybe you are looking for

  • Invoking a Web Service from EJB

    Hi I need to invoke a web serice from existing EJB(stateless session bean) deployed in J2EE SDK 1.3.1. I have downloaded Java WSDP but I have no idea where to start. Can any one briefly explain to me how to do this ? Thanks.

  • Javascript popup in dynamic report

    Hello, I want to be able to use Javascript popup window from a dynamic report in Apex 4.0. Is there anything built-in to help me out? Or should I use my own javascript function in the header and call it? My idea would be that one column would have a

  • Hdcp error

    I am getting the HDCP playback error today for some reason when I rented a movie. I rented one the other night with no problems. I cannot even watch movies that I have on my imac on my apple tv because of this error. please help.

  • 6085 won't switch on or charge

    I just bought a 6085 today, got it home and put the sim card and battery in properly, plugged in the charger, and nothing happened. I have unplugged the charger and plugged it back in again, I have tried different power points around the house, I hav

  • RE: the "De activating / un registering cs2..." thread

    Jim and Neil... Jim said: "It is unlikely that many here will feel moved to assist a new thread on the topic to aid blatant abuse of licensing..." and, Neil said: "As Jim is saying: that's illegal; a.k.a. piracy. Please understand that you cannot ins