Read data from console and print in one file. That would be
in C:\temp ? Thanks, Bose

Answers were Sorted based on User's Feedback



Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose..

Answer / 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

Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose..

Answer / avi

@Pushpa...
If u r reading console data from the method other than main() then u need to use Console class and scanner.

And use StringBuffer in place of String as when u r using '+' operator it creates new string object. So use StringBuffer and use API append("").

Is This Answer Correct ?    1 Yes 0 No

Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose..

Answer / ravi jain

good answer pushpa.. :)

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Core Java Interview Questions

how its run?

0 Answers  


Where can I find data structures question and answers with comprehensive working code written in Java

0 Answers   Amazon,


how to make the double-tone class ? as we have singletone class..?

1 Answers   IBM, Microsoft,


What is the locale class in java programming?

0 Answers  


what is a static block?

4 Answers  






How can we create a object of a class without using new operator.

1 Answers   Infosys, Nokia,


What are the main differences between the java platform and other platforms?

0 Answers  


How do I stop concurrentmodificationexception?

0 Answers  


Tell us something about set interface.

0 Answers  


What is a finally block?

0 Answers  


How can I become a good programmer?

0 Answers  


How to store image in arraylist in java?

0 Answers  


Categories