Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CMD to file 1

Status
Not open for further replies.

rohansr002

Programmer
Feb 19, 2010
15
IN
How to get data from command promt to File in java. please help
 
Try and play with this..
Code:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

PrintWriter pw=new PrintWriter(new File("filename"));

String line;
while((line=br.readLine()) !=null){
 pw.write(line);
 pw.flush();
}
 
For writing a single line to a file you could use this:
Code:
try {
	//create a buffered reader that connects to the console, we use it so we can read lines
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	//read a line from the console
	String lineFromInput = in.readLine();

	//create an print writer for writing to a file
	PrintWriter out = new PrintWriter(new FileWriter("output.txt"));

	//output to the file a line
	out.println(lineFromInput);

	//close the file (VERY IMPORTANT!)
	out.close();
} catch (IOException e) {
	System.out.println("Error during reading/writing");
}
 
typeperf "\Memory\Available bytes" "\processor(_total)\% processor time".........THis code i have to run through Java Code...
1. How to run this through Java
2. how to get this data into file through CMD....
 
I mean use an example like this and replace the command with the one you need.

If you have problems you can come back to us for help, but I wouldn't expect anyone here to code it for you.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top