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 a window and a frame in java programming?
What is main string [] args?
What is oop principle in java?
What is the difference between overriding and overloading in OOPS.
How to calculate the length of a singly linked list in java?
what is heap memory?
Can we declare an interface as final?
Why char array is preferred over string for storing password?
What is a variable and constant?
What is a class object?
Why is String immutable?
What is return keyword in java?
What are dot operator queries?
Which programming language is best in future?
What is the point of polymorphism java?