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;
    }

 

posted on 2015-06-09 18:39  乔叶叶  阅读(1822)  评论(0编辑  收藏  举报

导航