从电脑里读出有固定格式的txt文件,并将txt文件的各项数据解析出来.
import com.sun.deploy.util.StringUtils;
import java.io.*;
public class readText {
public static void main(String[] args) {
String path = "D:\test.txt";
try {
FileInputStream fileInputStream = new FileInputStream(path);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String string = "";
while ((string = bufferedReader.readLine()) != null){
String[] strings = StringUtils.splitString(string,"&");
for (int i = 0; i < strings.length; i++) {
System.out.println(strings[i]);
}
}
bufferedReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}