1.用java读取txt文件
public static String readFJ(String path) { path = "D:/workspace/hetong.txt"; File file = new File(path); StringBuffer txt= new StringBuffer(); if(file.isFile() && file.exists()) { //InputStreamReader in = null; try { InputStreamReader in = new InputStreamReader(new FileInputStream(file),"GBK"); BufferedReader bfd = new BufferedReader(in); String s; while((s=bfd.readLine())!=null) { txt.append(s); } in.close(); bfd.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return txt.toString(); }
2.用selenium读取txt文件
public static String readFS(String path) { File file = new File(path); String s = null; try { s = FileHandler.readAsString(file); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; }
时间: 2024-10-24 10:29:39