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
What is bom encoding?
Explain when we should make an instance variable private.
What is multiple inheritance? Is it supported by java?
How does the java compiler work?
Is static variable stored in heap?
What do you mean by platform independence?
What is a numeric string?
What does java stand for?
What are new features introduced with java 8 ?
Does substring start with 0?
What is an infinite loop? How infinite loop is declared?
What does the @override annotation do?
Java.util.regex consists of which classes?
Can you access non static variable in static context?
What is Gang of four design patterns