java.lang.String.split(ss) :
将一个字符串分割为子字符串,然后将结果作为字符串数组返回
ss:用来分割的依据;"\\." 或者"\\\\"
public class Test {
public static void main(String[] args) {
String fakeFileData = "D:\\myprojects\\mywork\\11.txt";
String[] tokens = fakeFileData.split("\\\\");
for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
}
}
D:\\myprojects\\mywork\\11.txt 输出结果:
D:
myprojects
mywork
11.txt
output