Solved

reading values out into a file

Posted on 1998-07-30
8
260 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 43
split string containing \r\n in Java 46 44
how to add new optional parameter to JSP 1 41
String array comparison 4 34
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

778 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