Solved

reading values out into a file

Posted on 1998-07-30
8
252 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
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
 
LVL 4

Expert Comment

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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now