Read data from console and print in one file. That would be
in C:\temp ? Thanks, Bose
Answer Posted / 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 |
Post New Answer View All Answers
What is default locale java?
What are the advantages of defining packages in java?
What are internal variables?
What is the difference between stringbuffer and stringbuilder class?
List some oops concepts in java?
Can inner class have constructor?
What are different ways of object creation in java ?
Can I use % with real numbers?
Explain methods specific to list interface?
What are the Static and Dynamic Variables? Differentiate them.
What is getclass () getname () in java?
What is a priority queue java?
When is finally block not called?
What is the difference between declaration and definition in java?
How do you achieve polymorphism in java?