Hi,
I am using 7zip in command line mode.
When the operation takes quite a long time, sometimes there is a process percentage displayed.
I wonder if we want to do this using C#/Java, what library to use?
Regards,
Hi,
I am using 7zip in command line mode.
When the operation takes quite a long time, sometimes there is a process percentage displayed.
I wonder if we want to do this using C#/Java, what library to use?
Regards,
no library. You just print to the console System.out.print (not println!), then send backspace characters to clear the line.
System.out("Progress 5");
System.out("\b\b\b\b\b\b\b\b\b\b");
System.out("Progress 10");
I haven't done this in awhile, but that should do it.
You can print a "carriage return", also known as a '\r'
to reset the "cursor" to the start of the line.
System.out.printf("Progress: %3d %% \r", percentComplete);
Now every time you print the line, you get sent back to the start so the next percent overwrites the previous one.
You could clear the console for kicks...oh and don't forget string.format has percentage support...
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var perc = 0.0;
while(perc <= 1.0)
{
Threading.Thread.Sleep(50); //simulate doing some work
//EDIT:
//Console.Clear();
Console.Write(String.Format("{0:P}\r", perc)); //as per suggestion
perc += 0.01;
}
Console.WriteLine("Press any key to exit");
var exit = Console.ReadKey();
}
}
}