selenium读取txt文件的几种方式

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;
    }
原文地址:https://www.cnblogs.com/qiaoyeye/p/4564272.html