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
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 |
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 |
What are integer overflows and underflows and how to handle them?
Java Compiler is stored in JDK, JRE or JVM?
Explain oops concepts in detail?
Can we make the abstract methods static in java?
How does java pattern compile work?
String and stringbuffer both represent string objects. Can we compare string and stringbuffer in java?
What is empty string literal in java?
What are the different collection views provided by maps?
What is the default initialized value of a boolean type variable?
What is method overriding in java ?
What is a lambda expression ? What's its use ?
Is alive and join method in java?