Read data from console and print in one file. That would be
in C:\temp ? Thanks, Bose
Answers were Sorted based on User's Feedback
Answer / pushpa
//Read data from console and print in one file.
import java.io.*;
class ReadDataFromConsole
{
public static void main(String[] args)
{
try{
String fileStr = ""; // declare a string variable
for(int i = 0; i<args.length; i++){ // for loop start
with argument size
fileStr = fileStr + " " + args[i];
}
//create an instance of the random acces file "rfile'.
RandomAccessFile rfile = new
RandomAccessFile("C:/Temp/text.txt","rw");
// write object into the file.
rfile.writeBytes(fileStr);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / avi
@Pushpa...
If u r reading console data from the method other than main() then u need to use Console class and scanner.
And use StringBuffer in place of String as when u r using '+' operator it creates new string object. So use StringBuffer and use API append("").
| Is This Answer Correct ? | 1 Yes | 0 No |
What are the features of junit?
what is the use of thread?Justify it by project point of view
What is the use of using enum to declare a constant?
What are untrusted applets?
How can u increase the heap size in the memory?
Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..
What is the disadvantage of java?
What is singleton class in java and how can we make a class singleton?
What is the format specifier?
Java.util.regex consists of which classes?
write the hierarchy of component class?
I don’t want my class to be inherited by any other class. What should I do?