转存

原创 2015年07月11日 00:51:45
package com.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Command {
	public static void exeCmd(String commandStr) {
		BufferedReader br = null;
		try {
			Process p = Runtime.getRuntime().exec(commandStr);
			br = new BufferedReader(new InputStreamReader(p.getInputStream(),"gbk"));
			String line = null;
			StringBuilder sb = new StringBuilder();
			while ((line = br.readLine()) != null) {
				sb.append(line + "\n");
				System.out.println(sb.toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		finally
		{
			if (br != null)
			{
				try {
					br.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void bbbb() {
		try {  
		    Runtime rt = Runtime.getRuntime();  
		    Process proc = rt.exec("javac");  
		    int exitVal = proc.waitFor();  
		    System.out.println("Process exitValue: " + exitVal);    
		} catch (Throwable t) {  
		    t.printStackTrace();  
		} 
	}
	
	public static void cccc() {
		BufferedReader br = null;
		try {  
			//String [] cmd={"cmd","/C","copy exe1 exe2"};
			String [] cmd={"diskpart","list disk"}; 
			Process p = Runtime.getRuntime().exec(cmd);
			br = new BufferedReader(new InputStreamReader(p.getInputStream(),"gbk"));
			String line = null;
			StringBuilder sb = new StringBuilder();
			while ((line = br.readLine()) != null) {
				sb.append(line + "\n");
				System.out.println(sb.toString());
			}
		} catch (Throwable t) {  
		    t.printStackTrace();  
		} 
	}
	
	public static void dddd() {
		try {  
		    Runtime rt = Runtime.getRuntime();  
		    String [] cmd={"diskpart","list disk"}; 
		    Process proc = rt.exec(cmd);  
		    InputStream stderr = proc.getErrorStream();  
		    InputStreamReader isr = new InputStreamReader(stderr,"GBK");  
		    BufferedReader br = new BufferedReader(isr);  
		    String line = null;  
		    System.out.println("<ERROR>");  
		    while ((line = br.readLine()) != null)  
		        System.out.println(line);  
		    System.out.println("</ERROR>");  
		    long exitVal = proc.waitFor();  
		    System.out.println("Process exitValue: " + exitVal);  
		} catch (Throwable t) {  
		    t.printStackTrace();  
		}  
	}
	
	public static void eeee(){
		File[] roots = File.listRoots();
		for (File drive : roots) {
		   System.out.println(drive.getPath());
		  }
		 System.out.println("***MAC地址***");  
	        //****************获取硬盘ID*****************//  
	        String sn = DiskUtils.getSerialNumber("C");   
	        System.out.println("***硬盘编号***");  
	        System.out.println(sn);   
	}
	
	public static void main(String[] args) {
		//String commandStr = "ping www.taobao.com";
		String commandStr = "diskpart ; list disk";
		//Command.exeCmd(commandStr);
		//bbbb();
//		cccc();
//		dddd();
		eeee();
	}
}
</pre><pre name="code" class="java">
package com.utils;


import java.io.File;


import javax.swing.filechooser.FileSystemView;


/**
 * 磁盘检查
 * 1、检测磁盘是本地磁盘还是可移动磁盘;
 * 2、显示相应的磁盘名称,磁盘总空间以及可用的空间
 */
public class DiskTest {
<span style="white-space:pre">	</span>private final static String localDiskName = "本地磁盘";
<span style="white-space:pre">	</span>private final static String removableDiskName = "可移动磁盘";
<span style="white-space:pre">	</span>private final static String enLocalDiskName = "Local Disk";
<span style="white-space:pre">	</span>private final static String enRemovableDiskName = "Removable Disk";


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * 获取磁盘信息
<span style="white-space:pre">	</span> * @return Map<String,ReturnPo>
<span style="white-space:pre">	</span> */


<span style="white-space:pre">	</span>public static void getDiskInfo() {
<span style="white-space:pre">		</span>FileSystemView fileSystemView = FileSystemView.getFileSystemView();// 获取FileSystemView对象
<span style="white-space:pre">		</span>File[] roots = File.listRoots();
<span style="white-space:pre">		</span>for (File file : roots) {
<span style="white-space:pre">			</span>String pathName = file.getPath();// 获取磁盘的路径名称
<span style="white-space:pre">			</span>String diskName = fileSystemView.getSystemTypeDescription(file);// 获取磁盘的类型描述信息
<span style="white-space:pre">			</span>if (diskName.startsWith(localDiskName)
<span style="white-space:pre">			</span>|| diskName.startsWith(enLocalDiskName))// 当磁盘为本地磁盘时
<span style="white-space:pre">			</span>{
<span style="white-space:pre">			</span>} else if (diskName.startsWith(removableDiskName)
<span style="white-space:pre">			</span>|| diskName.startsWith(enRemovableDiskName))// 当磁盘为可移动磁盘时
<span style="white-space:pre">			</span>{
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>System.out.println("磁盘名称为:" + diskName + pathName);
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>/**
<span style="white-space:pre">	</span> * @param args
<span style="white-space:pre">	</span> */


<span style="white-space:pre">	</span>public static void main(String[] args) {
<span style="white-space:pre">		</span>DiskTest.getDiskInfo();
<span style="white-space:pre">	</span>}
}
</pre><pre name="code" class="java">
</pre><pre name="code" class="java">package com.utils;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
  
class DiskUtils {  
    private DiskUtils() {  
    }  
  
    public static String getSerialNumber(String drive) {  
        String result = "";  
        try {  
            File file = File.createTempFile("d00000000", ".txt");
            FileWriter fw = new java.io.FileWriter(file);
            String vbs = "list disk"; // see note
            fw.write(vbs);
            fw.close();
            Process p = Runtime.getRuntime().exec("diskpart /s " + file.getPath());
            System.out.println(file.getPath());
            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));  
            String line;
            while ((line = input.readLine()) != null) {
            <span style="white-space:pre">	</span>System.out.println(line);
            }  
            input.close();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return result.trim();  
    }  
}  

相关文章推荐

RGBA数据转存BMP图片

  • 2017年09月06日 11:51
  • 3KB
  • 下载

解决word2007转存pdf问题的补丁

  • 2010年08月22日 13:34
  • 933KB
  • 下载

ajax异步上传图片webservice转存图片服务器

项目源代码及相关jar包:https://github.com/smallbug-vip/repo/tree/master/code/web/back  一、搭建SpringMVC环境  ...
  • sqzhao
  • sqzhao
  • 2016年02月03日 08:58
  • 1185

转存精灵2005

  • 2013年06月17日 00:35
  • 192KB
  • 下载

Android 调用系统的照相,浏览图片,转存并裁剪!

public class AddCardActivity extends Activity { private  Button add; private  Button tak...

bmp图片转存代码

  • 2014年07月04日 14:54
  • 19KB
  • 下载

PB导入excel转存txt

  • 2011年09月08日 22:28
  • 1004B
  • 下载

doc,excel,ppt转存pdf并预览

需要jar包: 下载aspose-words-15.8.0-jdk16.jar包http://pan.baidu.com/s/1nvbJwnv 下载aspose-cells-8.5.2.jar包 h...

百度网盘批量转存工具

  • 2014年12月12日 18:35
  • 1.25MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:转存
举报原因:
原因补充:

(最多只允许输入30个字)