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 the difference between Object Based Language and Object Oriented Language?
Can we force garbage collector to run ?
How do you print array in java?
Can we override singleton class?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
What is array list in java?
What is difference between float and double?
What is isa relationship?
What is the base class of all exception classes in java?
Which language is java?
Can we compare two strings in java?
What modifiers may be used with an inner class that is a member of an outer class in java programming?
What is the difference between compile-time polymorphism and runtime polymorphism?
What is the meaning of 3 dots in java?
How many bytes are there?