标签: readfile

Python - 从文件中读取第二列

我的输入文件有两列.我试图在第二inputdata1.txt个for循环中打印第二列.但我的代码不起作用.有人可以告诉我该怎么办?

python file-io for-loop readfile

8
推荐指数
3
解决办法
5万
查看次数

无法解析为整数

好吧......我有这个.txt文件(UTF-8)

4661,SOMETHING,3858884120607,24,24.09
4659,SOMETHING1,3858884120621,24,15.95
4660,SOMETHING2,3858884120614,24,19.58
Run Code Online (Sandbox Code Playgroud)

而这段代码

FileInputStream fis = new FileInputStream(new File(someTextFile.txt));
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader in = new BufferedReader(isr);

int i = 0;
String line;
while((line = in.readLine()) != null) {
Pattern p = Pattern.compile(",");
String[] article = p.split(line);

// I don't know why but when a first line starts with
// an integer - article[0] (which in .txt file is 4661)
// becomes someWeirdCharacter4661 so I need to trim it
// *weird character is like |=>| …
Run Code Online (Sandbox Code Playgroud)

android parseint readfile

7
推荐指数
1
解决办法
1万
查看次数

同时读取两个文本文件-java

我有两种不同语言的文本文件,它们是逐行对齐的.即textfile1中的第一行应该等于textfile2中的第一行,依此类推.

有没有办法同时逐行读取这两个文件?

下面是文件应该如何显示的示例,假设每个文件的行数大约为1,000,000.

textfile1:

This is a the first line in English
This is a the 2nd line in English
This is a the third line in English
Run Code Online (Sandbox Code Playgroud)

textfile2:

C'est la première ligne en Français
C'est la deuxième ligne en Français
C'est la troisième ligne en Français
Run Code Online (Sandbox Code Playgroud)

期望的输出

This is a the first line in English\tC'est la première ligne en Français
This is a the 2nd line in English\tC'est la deuxième ligne en Français
This is a the third line …
Run Code Online (Sandbox Code Playgroud)

java io text-files readfile

7
推荐指数
1
解决办法
1万
查看次数

从 Amazon s3 流读取文本

我使用以下代码从 Amazon S3 读取文本文件,并逐行处理它。这段代码可以工作,但问题是速度很慢。

 GetObjectRequest getObjRequest = new GetObjectRequest()
    .WithBucketName(amazonSettings.BucketName)
    .WithKey(_fileKey);
using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(
    amazonSettings.AccessKey, 
    amazonSettings.SecretAccessKey))
using (GetObjectResponse getObjRespone = client.GetObject(getObjRequest))
using (Stream amazonStream = getObjRespone.ResponseStream)
{                        
    StreamReader amazonStreamReader = new StreamReader(amazonStream);
    tempGsContact = new GSContact();
    while ((_fileLine = amazonStreamReader.ReadLine()) != null)
    {
        if (_fileLine.Equals("END:VCARD"))
        {
            // Make process 1
        }
        else if (!_fileLine.Equals(string.Empty))
        {
            //Make process 2
        }
    }                        
}
Run Code Online (Sandbox Code Playgroud)

问题是:我能否得到更充分的方式来降低时间成本?

c# readline amazon-s3 streamreader readfile

7
推荐指数
1
解决办法
2万
查看次数

C# - 定期读取文件最后一部分的最有效方法

我想定期读取也正在写入的日志文件.该程序将定期读取日志文件内容并解析它以提取一些值.但我不想每次都阅读整个文件.

有没有办法从特定的行开始读取文件?

例如,在第一次读取时,文件有100行.我注意到这个值,下次我读到时我开始从第100行开始读取并存储当前文件的行号.

有没有一种有效的方法来做到这一点?日志文件将增长到大约100MB,我需要每5秒阅读一次.因此,每次读取完整文件的效率都不高.

任何建议都非常感谢.

c# readfile

7
推荐指数
1
解决办法
1218
查看次数

Golang如何在Go中读取输入文件名

我想运行我的go文件,当我输入go run命令时input.txt,我的go程序将读取input.txt文件,即:

go run goFile.go input.txt
Run Code Online (Sandbox Code Playgroud)

我不想放入input.txt我的goFile.go代码,因为我的go文件不应该只在任何输入名称上运行input.txt.

我尝试ioutil.ReadAll(os.Stdin)但我需要改变我的命令

go run goFile.go < input.txt
Run Code Online (Sandbox Code Playgroud)

我只用包fmt,os,bufioio/ioutil.没有任何其他包装可以做到吗?

file go readfile

7
推荐指数
1
解决办法
5828
查看次数

readFile 是否缓存内容?

假设我有:

var fs = require('fs');
var a= fs.readFile(__dirname + '/someBigFile.txt', function(err, data) {
    console.log(data);
});
Run Code Online (Sandbox Code Playgroud)

我注意到,如果最初需要 2 秒来读取someBigFile,现在则需要几毫秒。当您多次读取 Node.js 时,是否会发生一些内部缓存?例如:

for(var i =0; i < 10000; i++)
{
    var greet = fs.readFile(__dirname + '/greet.txt', "utf-8", function(err, data) {
    });
}
Run Code Online (Sandbox Code Playgroud)

fs readfile node.js

7
推荐指数
1
解决办法
5745
查看次数

颤动:如何加载文件进行测试

可以从相对于dart脚本文件的目录中读取文件,简单如下var file = new File('./fixture/contacts.json').

但是文件无法读取在IDE内运行的颤动测试.

作为资源加载(它不是,因为我不想在应用程序中捆绑测试数据文件)也不能在测试中工作.

在flutter中读取文件的好方法是什么(对于命令行测试和IDE测试)?

跑步flutter test非常快.但是,Intellij IDE内部的测试速度很慢,但它可以设置调试断点并进入并查看变量.所以这两种测试都非常有用.

testing intellij-idea readfile flutter

7
推荐指数
4
解决办法
2009
查看次数

在Python中读取SPSS(.sav)文件时出现"标题已被用作名称或标题"错误

我正在研究一个SPSS文件(.sav).我下面的代码可以读取.sav文件.但是,我遇到了一个非常奇怪的错误.当我尝试读取另一个.sav文件时,它会出现以下错误

Traceback (most recent call last):
File "C:\Users\fatihshen\Documents\Merjek 
Project\Predictive_Analytics\sav_reader.py", line 28, in <module>
read_spss_file(file_path)
File "C:\Users\fatihshen\Documents\Merjek 
Project\Predictive_Analytics\sav_reader.py", line 10, in read_spss_file
records = reader.all()
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\savReaderNp.py", line 541, in all
return self.to_structured_array(filename)
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\savReaderNp.py", line 122, in _convert_datetimes
array = func(self, *args)
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\savReaderNp.py", line 148, in _convert_missings
array = func(self, *args)
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\savReaderNp.py", line 531, in to_structured_array
array = np.fromiter(self, self.trunc_dtype, self.nrows)
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\helpers.py", line 17, in fget_memoized
setattr(self, attr_name, fget(self))
File "C:\Users\fatihshen\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\savReaderWriter\savReaderNp.py", …
Run Code Online (Sandbox Code Playgroud)

python spss readfile

7
推荐指数
1
解决办法
1505
查看次数

使用 PyGitHub 读取 GitHub 中的文件内容

让\xe2\x80\x99s 说“sample.txt”文件位于GitHub 中的“Demo”存储库[Demo/sample.txt] 下。如何使用PyGitHub读取example.txt的内容而不是从 API 获取?

\n

否则,我们是否有其他包来读取此类文件内容?

\n

python github readfile pygithub

7
推荐指数
1
解决办法
6800
查看次数