我试图计算Windows中已用磁盘空间的百分比,而totaldrive表示Long中的C驱动器的总磁盘空间和Long中的freedrive dentoes可用空间.
long totaloccupied = totaldrive - freedrive;
Run Code Online (Sandbox Code Playgroud)
这里计算使用百分比
Long Percentageused =(totaloccupied/totaldrive*100);
System.out.println(Percentageused);
Run Code Online (Sandbox Code Playgroud)
print语句返回0.有人可以提供帮助,因为我没有得到所需的值
我有以下代码来复制目录和文件,但不知道在哪里测量进度.有人可以帮助
我在哪里可以测量复制了多少并在JProgress栏中显示它
public static void copy(File src, File dest)
throws IOException{
if(src.isDirectory()){
if(!dest.exists()){ //checking whether destination directory exisits
dest.mkdir();
System.out.println("Directory copied from "
+ src + " to " + dest);
}
String files[] = src.list();
for (String file : files) {
File srcFile = new File(src, file);
File destFile = new File(dest, file);
copyFolder(srcFile,destFile);
}
}else{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0){ …
Run Code Online (Sandbox Code Playgroud) 我想检查Swing中的用户名和密码.
该检查适用于用户名,但它不适用于JPaswordfield.我发布相关代码:
//Here I get the password
Char[] pwd = jt1.getPassword();
String s = new String(pwd); //converting char to string
String p = s;
//In the JButton checking username and password(Username check works fine but not passwordfield)
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if ((jt.getText().length()) == 0)
{
JFrame jf1 = new JFrame("UserName");
jf1.setSize(401, 401);
//jf1.setVisible(true);
jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);
JOptionPane.showMessageDialog(jf1, "User Name is empty");
}
else if((p.length()) == 0)
{
JFrame jf1 = new JFrame("Password");
jf1.setSize(401, 401);
//jf1.setVisible(true);
jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);
JOptionPane.showMessageDialog(jf1, …
Run Code Online (Sandbox Code Playgroud)