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 queue in java?
Why we use protected in java?
How many types of memory areas are allocated by jvm?
How to set the permissions to a file in java?
What are abstract classes and anonymous classes?
What is the use of set in java?
Explain about field hiding in java?
How to remove the trailing spaces from a string?
How is it possible for two string objects with identical values not to be equal under the == operator?
What is field name?
What is primitive data type in java?
what is abstract class in Java?
What is package private scope in java?
What does java se mean?
What is the reflection?