4 changed files with 206 additions and 12 deletions
-
58src/main/java/com/iflytop/handacid/app/common/utils/UsbDriverUtil.java
-
74src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java
-
11src/main/java/com/iflytop/handacid/app/controller/FormulationController.java
-
75src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java
@ -0,0 +1,58 @@ |
|||||
|
package com.iflytop.handacid.app.common.utils; |
||||
|
|
||||
|
import java.io.File; |
||||
|
|
||||
|
public class UsbDriverUtil { |
||||
|
/** |
||||
|
* 查找 win U盘路径 |
||||
|
* @return U盘路径,如果找不到返回null |
||||
|
*/ |
||||
|
public static String findWinPath() { |
||||
|
// Windows系统查找可移动驱动器 |
||||
|
File[] roots = File.listRoots(); |
||||
|
for (File root : roots) { |
||||
|
// 检查是否为可移动驱动器(U盘) |
||||
|
if (root.getTotalSpace() > 0 && root.getTotalSpace() < 64L * 1024 * 1024 * 1024) { // 小于64GB认为是U盘 |
||||
|
String rootPath = root.getAbsolutePath(); |
||||
|
// 检查是否可写 |
||||
|
if (root.canWrite()) { |
||||
|
return rootPath; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查找Linux U盘路径 |
||||
|
* @return U盘路径,如果找不到返回null |
||||
|
*/ |
||||
|
public static String findLinuxPath(){ |
||||
|
// Linux/Mac系统查找/media或/run/media下的可移动设备 |
||||
|
String[] mediaPaths = {"/media", "/run/media"}; |
||||
|
for (String mediaPath : mediaPaths) { |
||||
|
File mediaDir = new File(mediaPath); |
||||
|
if (mediaDir.exists() && mediaDir.isDirectory()) { |
||||
|
File[] subDirs = mediaDir.listFiles(); |
||||
|
if (subDirs != null) { |
||||
|
for (File subDir : subDirs) { |
||||
|
if (subDir.isDirectory() && subDir.canWrite()) { |
||||
|
return subDir.getAbsolutePath(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public static String findPath() { |
||||
|
String osName = System.getProperty("os.name").toLowerCase(); |
||||
|
if (osName.contains("win")) { |
||||
|
return findWinPath(); |
||||
|
} else { |
||||
|
return findLinuxPath(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue