Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reading values out into a file

Posted on 1998-07-30
8
Medium Priority
?
289 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 140 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 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