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 queue in java?

809


Why we use protected in java?

727


How many types of memory areas are allocated by jvm?

769


How to set the permissions to a file in java?

750


What are abstract classes and anonymous classes?

850


What is the use of set in java?

848


Explain about field hiding in java?

716


How to remove the trailing spaces from a string?

889


How is it possible for two string objects with identical values not to be equal under the == operator?

742


What is field name?

774


What is primitive data type in java?

730


what is abstract class in Java?

877


What is package private scope in java?

714


What does java se mean?

773


What is the reflection?

777