Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

What is the final variable?

1 Answers  


What is the longest unicode character?

0 Answers  


Why stringbuilder is not thread safe in java?

0 Answers  


What is the difference between Integer and int?

10 Answers   Infosys,


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

0 Answers   Akamai Technologies,


how to call a method in different package?

4 Answers  


how to call One constructor from another;

10 Answers   Innodata Isogen,


What is a double?

0 Answers  


Which collection is sorted in java?

0 Answers  


if arraylist size is increased from initial size what is the size of arraylist...suppose initial is 100 , if i add 101 element what is the size...

10 Answers  


Why is it called buffering?

0 Answers  


can we access the super class method using subclass object?

4 Answers  


Categories