alanmin
asked on
reading values out into a file
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..
All help appreciated..
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?
ASKER
Evijay that doesn't work for me I get an error saying the printsteam has been depreciated by the authors.
use PrintWriter and FileWriter instead of PrintStream and FileStream
ASKER
public void actionPerformed(ActionEven t 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:/WINDO WS/Desktop /Aljava/Pr oject2/pla ne.txt");
prt = new PrintWriter(fos);
}
catch(IOException e){
}
for (j=0; j<14; j++) {
air[count][j] = String.valueOf(tf[j].getTe xt());
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??
//****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:/WINDO
prt = new PrintWriter(fos);
}
catch(IOException e){
}
for (j=0; j<14; j++) {
air[count][j] = String.valueOf(tf[j].getTe
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??
do you want the complete code? if so do lay down the specific requirements. eg GUI? ......
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
Hope this helps some --
Alexander Wilkins
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.t
PrintStream ps = new PrintStream(fos);
ps.println(lineofTextread)