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;
    }
时间: 2024-08-25 00:18:44

selenium读取txt文件的几种方式的相关文章

java读取XML文件的四种方式

java读取XML文件的四种方式 Xml代码 <?xml version="1.0" encoding="GB2312"?> <RESULT> <VALUE> <NO>A1234</NO> <ADDR>河南省郑州市</ADDR> </VALUE> <VALUE> <NO>B1234</NO> <ADDR>河南省郑州市二七区&

JavaWeb读取资源文件的四种方式

1. ServletContext 1. 调用getResourcesAsStream方法获取输入流, 相对于webroot, 不用加/2. 读取任何类型的文件3. *只能在web环境下使用 InputStream in = this.getServletContext().getResourceAsStream("WEB-INF/classes/config/db.properties"); 2. 类加载器 1. 相对于类路径, 可以获取类路径下及其子包路径下的资源文件2. 可以用在

43. C# -- 读取TXT文件的两种方法

1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出.         public void Read()         {                      byte[] byData = new byte[100];                    char[] charData = new char[1000];             try        

读取XML文件的几种方式的效率分析

第一种:使用XmlReader来读取. 1 Stopwatch sw = Stopwatch.StartNew(); 2 List<Dictionary<string, string>> entityInfo = new List<Dictionary<string, string>>(); 3 using (XmlReader reader = new XmlTextReader(compareXmlName)) 4 { 5 Dictionary<s

快速读取大文件的几种方式

转一篇:http://blog.csdn.net/fengxingzhe001/article/details/67640083 原来使用一行一行读取文本的方式,速度是慢的的可以,弄了好久还是不行,后来看了下才知道要用字节流传输会快很多 我自己也测了一下80M的文件,发现给读入块的大小会很明显的影响读入的速度. 测试代码如下: def useBufferIStream(): Util = { try { val begin = System.currentTimeMillis val file

java读取excel文件的两种方式

方式一: 借用 package com.ij34.util; /** * @author Admin * @date 创建时间:2017年8月29日 下午2:07:59 * @version 1.0 *@type_name myclass */ import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.B

Python之读取TXT文件的三种方法

参考了https://blog.csdn.net/shandong_chu/article/details/70173952 -- coding: UTF-8 -- import sys 方法一:#read txt method one f = open("./image/abc.txt") line = f.readline() while line: print line line = f.readline() f.close() 方法二:#read txt method two

读取csv文件的两种方式

第一种: import csv with open("route.csv","r") as f: #reader是一个迭代器 reader=csv.reader(f) next(reader) #输出结果会去掉行头标题 for row in reader: name=row[0] dates=row[-1] print({"name":name,"date":dates}) 第二种: import csv with open(

C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式

前言 作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路! 程序界面 功能说明 打开文件按钮,可以由使用者指定要操作的Excel文件,并在后面的textBox中显示出文件路径. 设置单元格按钮,可以根据程序设置Excel文件的内容. 退出程序按钮,关闭窗体. 程序源代码 1 using System; 2 using System.Collections.Generic; 3 using System.Com