Solved

reading values out into a file

Posted on 1998-07-30
8
242 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 45
topping1 challenge 7 53
Modeling a class in java 5 33
Core Java. What output will be and why ? 6 58
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

746 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

14 Experts available now in Live!

Get 1:1 Help Now