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
Is 0 true or false in java?
What is the purpose of java?
Explain 5 io best practices?
Is string is a class in java?
Explain about member inner classes?
what is use of functional interface in java 8?
Why is string class considered immutable?
What is tree in java?
What are the data types supported by java? What is autoboxing and unboxing?
Why java does not support pointers?
Can I declare a class as private?
When would you use a static class?
What is heterogeneous in java?
What do you mean by ternary operator in java?
Explain the Propertie sof class?