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


Please Help Members By Posting Answers For Below Questions

What is the difference between a window and a frame in java programming?

867


What is main string [] args?

748


What is oop principle in java?

757


What is the difference between overriding and overloading in OOPS.

828


How to calculate the length of a singly linked list in java?

789


what is heap memory?

872


Can we declare an interface as final?

788


Why char array is preferred over string for storing password?

849


What is a variable and constant?

785


What is a class object?

706


Why is String immutable?

847


What is return keyword in java?

828


What are dot operator queries?

874


Which programming language is best in future?

736


What is the point of polymorphism java?

766