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

Is 0 true or false in java?

515


What is the purpose of java?

558


Explain 5 io best practices?

595


Is string is a class in java?

525


Explain about member inner classes?

590






what is use of functional interface in java 8?

561


Why is string class considered immutable?

598


What is tree in java?

491


What are the data types supported by java? What is autoboxing and unboxing?

549


Why java does not support pointers?

561


Can I declare a class as private?

592


When would you use a static class?

584


What is heterogeneous in java?

495


What do you mean by ternary operator in java?

560


Explain the Propertie sof class?

586