Solved

reading values out into a file

Posted on 1998-07-30
8
280 Views
Last Modified: 2010-03-30
I am asking the user to input 14 values of text and every time he presses an enter button these values will be sent to a file (it should only happen three times)...how do i go about this arduous (spelt right?) task

All help appreciated..
0
Comment
Question by:alanmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:evijay
ID: 1229283
DataInputStream dis = new DataInputStream(System.in);

now use dis.readLine() function to read 14 lines of text in a for loop.
Then use FileOutputStream like this

FileOutputStream fos = new FileOutputStream("myfile.txt");
PrintStream ps = new PrintStream(fos);

ps.println(lineofTextread);


0
 
LVL 2

Expert Comment

by:shchuka
ID: 1229284
Please explain a bit more what you're trying to do.  Why do you need to save 3 times, when asking for 14 inputs?  Or do you need to save one input at a time - 14 inputs together - and the whole thing goes on for 3 times?
0
 

Author Comment

by:alanmin
ID: 1229285
Evijay that doesn't work for me I get an error saying the printsteam has been depreciated by the authors.
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 4

Expert Comment

by:evijay
ID: 1229286
use PrintWriter and FileWriter instead of PrintStream and FileStream

0
 

Author Comment

by:alanmin
ID: 1229287
public void actionPerformed(ActionEvent ae)  {
      //****deals with the buttons pressed****//
            
            String str = ae.getActionCommand();
       
                  if(str.equals("Enter")) {
                        writeNums();
                        count++;
                  }
                  else if(str.equals("Reset")) {
                        resetit();
                  }
                  else if(str.equals("Show")) {
                        setVisible(false);
                        s.setVisible(true);
                  }
      }
      public      void writeNums(){
            try {
            fos = new FileOutputStream("C:/WINDOWS/Desktop/Aljava/Project2/plane.txt");
            prt = new PrintWriter(fos);
            }
            catch(IOException e){
            }
                  for (j=0; j<14; j++) {
                  air[count][j] = String.valueOf(tf[j].getText());
                  prt.write(air[count][j]);
                  }
            tf[0].setText(air[0][3]);
      }
evijay this is my code i had to use filewriter as when i compiled my code an error appeared that said that printstream was devaluated...what i really wish to happen is when error is pressed the data in the 14 textfields is stored in an 2-d array to take in to account that enter could be pressed three times...then each time it is pressed that data is also written to a file..i'm not sure why the above doesn't work??
0
 
LVL 1

Expert Comment

by:dryang
ID: 1229288
do you want the complete code? if so do lay down the specific requirements. eg GUI? ......
0
 

Expert Comment

by:awilkins
ID: 1229289
When the compiler generates a message that code is deprecated, it doesn't mean that the code doesn't work, it just means that there might be a better alternative to the manner in which your program functions.  The deprecation message is generally a warning, not an error, so class files are still generated and you can still run your program by typing java <classname> at the command prompt.
Hope this helps some --
             Alexander Wilkins
0
 
LVL 3

Accepted Solution

by:
sailwind earned 70 total points
ID: 1229290
printStream is a deprecated method of JDK 1.02. What this means is
that Java has a new and improved way of handling the printing operations.
It now uses the readers and writers to do the file IO. The deprecation is
Java's way of telling you: "Okay, this is an old method, and it will be
replaced soon. I will still use it right now, but be aware that it'll be
not be available in the future release. Please learn about newer implemen-
tations even though I will still compile and execute the program correctly"

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question