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 are the java ide's? Explain
What are access specifiers available in java?
What is stream api in java8?
Can long be null in java?
If an application has multiple classes in it, is it okay to have a main method in more than one class?
How is Object Oriented Programming different from Procedure Oriented Programming?
What is binary tree in java?
What is treeset and treemap in java?
Define Multiprogramming and Multiprocessing in java.
Explain different types of thread priorities ?
Can you inherit from an abstract class java?
What is the difference between overriding & overloading?
What is an inner class in java?
What is not thread safe?
What is the main purpose of java?