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
Which collection is ordered in java?
What is an example of a constant variable?
What is boolean strategy?
Can an unreferenced object be referenced again?
What is substring 1 in java?
Can we declare register variable as global?
Why is stringbuffer called mutable?
What does || mean in code?
What is lazy programming?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
If you do not want your class to be inherited by any other class. What would you do?
How many bytes is a string in java?
Does list allow duplicates in java?
how we can make a write-only class in java?
Explain the difference between an object-oriented programming language and object-based programming language?