可能重复:
如何在java中拆分字符串
FileSystemView fsv = FileSystemView.getFileSystemView();
File[] roots = fsv.getRoots();
for (int i = 0; i < roots.length; i++)
{
System.out.println("Root: " + roots[i]);
}
System.out.println("Home directory: " + fsv.getHomeDirectory());
Run Code Online (Sandbox Code Playgroud)
Root:C:\ Users\RS\Desktop主目录:C:\ Users\RS\Desktop
我想剪切根或主目录组件,如字符串C,用户,RS,桌面
String DeviceName = "Black USB (H:)";
Run Code Online (Sandbox Code Playgroud)
如何从JAVA中的字符串中分离"Black USB"和删除(H :),我需要在其他类的方法中进一步传递.