标签: io

使用标头解析C#中的CSV文件

是否有默认/官方/推荐的方法来解析C#中的CSV文件?我不想滚动自己的解析器.

此外,我已经看到人们使用ODBC/OLE DB通过Text驱动程序读取CSV的实例,很多人由于其"缺点"而不鼓励这种情况.这些缺点是什么?

Ideally, I'm looking for a way through which I can read the CSV by column name, using the first record as the header/field names. Some of the answers given are correct but work to basically deserialize the file into classes.

c# csv io file-io header

248
推荐指数
10
解决办法
30万
查看次数

如何检查文件锁?

有没有办法检查文件是否被锁定而不使用try/catch块?

现在,我所知道的唯一方法就是打开文件并抓住任何文件System.IO.IOException.

.net c# io filelock

246
推荐指数
10
解决办法
18万
查看次数

如何防止SIGPIPE(或正确处理它们)

我有一个小型服务器程序,它接受TCP或本地UNIX套接字上的连接,读取一个简单的命令,并根据命令发送一个回复.问题是客户端有时可能对答案没兴趣并且提前退出,因此写入该套接字将导致SIGPIPE并使我的服务器崩溃.什么是防止崩溃的最佳做法?有没有办法检查线的另一边是否还在读?(select()似乎在这里不起作用,因为它总是说套接字是可写的).或者我应该用处理程序捕获SIGPIPE并忽略它?

c io signals sigpipe broken-pipe

242
推荐指数
8
解决办法
19万
查看次数

用C++编写二进制文件的速度非常快

我正在尝试将大量数据写入我的SSD(固态硬盘).大量的我的意思是80GB.

我浏览网页寻求解决方案,但我想出的最好的是:

#include <fstream>
const unsigned long long size = 64ULL*1024ULL*1024ULL;
unsigned long long a[size];
int main()
{
    std::fstream myfile;
    myfile = std::fstream("file.binary", std::ios::out | std::ios::binary);
    //Here would be some error handling
    for(int i = 0; i < 32; ++i){
        //Some calculations to fill a[]
        myfile.write((char*)&a,size*sizeof(unsigned long long));
    }
    myfile.close();
}
Run Code Online (Sandbox Code Playgroud)

使用Visual Studio 2010进行编译并完全优化并在Windows7下运行,此程序最大可达20MB/s.让我感到困扰的是,Windows可以将文件从其他SSD复制到此SSD,速度介于150MB/s和200MB/s之间.所以至少快7倍.这就是为什么我认为我应该能够更快.

我有什么想法可以加快我的写作速度?

c++ io optimization performance file-io

221
推荐指数
8
解决办法
17万
查看次数

fprintf,printf和sprintf之间的区别?

任何人都可以用简单的英语有关之间的差异说明printf, fprintf以及sprintf结合实例?

它是什么流?

在阅读"C中的文件处理"时,我对其中的三个感到困惑.

c io printf stream

206
推荐指数
4
解决办法
20万
查看次数

如何使用open with语句打开文件

我正在研究如何在Python中进行文件输入和输出.我编写了以下代码来读取文件中的名称列表(每行一个)到另一个文件,同时根据文件中的名称检查名称,并将文本附加到文件中的出现位置.代码有效.可以做得更好吗?

我想对with open(...输入和输出文件使用该语句,但无法看到它们在同一块中的含义,这意味着我需要将名称存储在临时位置.

def filter(txt, oldfile, newfile):
    '''\
    Read a list of names from a file line by line into an output file.
    If a line begins with a particular name, insert a string of text
    after the name before appending the line to the output file.
    '''

    outfile = open(newfile, 'w')
    with open(oldfile, 'r', encoding='utf-8') as infile:
        for line in infile:
            if line.startswith(txt):
                line = line[0:len(txt)] + ' - Truly a great person!\n'
            outfile.write(line)

    outfile.close()
    return # …
Run Code Online (Sandbox Code Playgroud)

python io file-io file python-3.x

184
推荐指数
3
解决办法
53万
查看次数

我是否需要关闭()FileReader和BufferedReader?

我正在使用围绕FileReader的BufferedReader读取本地文件:

BufferedReader reader = new BufferedReader(new FileReader(fileName));
// read the file
// (error handling snipped)
reader.close();
Run Code Online (Sandbox Code Playgroud)

我需要close()FileReader为好,或将包装处理这个问题?我见过人们这样做的代码:

FileReader fReader = new FileReader(fileName);
BufferedReader bReader = new BufferedReader(fReader);
// read the file
// (error handling snipped)
bReader.close();
fReader.close();
Run Code Online (Sandbox Code Playgroud)

从servlet调用此方法,我想确保不打开任何句柄.

java io filereader bufferedreader

179
推荐指数
5
解决办法
15万
查看次数

cout不是std的成员

我正在练习使用多个文件和头文件等.所以我有这个项目需要两个数字,然后添加它们.很简单.

这是我的文件:

main.cpp中

#include <iostream>
#include "add.h"

int main()
{
    int x = readNumber();
    int y = readNumber();

    writeAnswer(x + y);

    return(0);
}
Run Code Online (Sandbox Code Playgroud)

io.cpp

int readNumber()
{
    int x;

    std::cout << "Number: ";
    std::cin >> x;

    return x;
}

void writeAnswer(int x)
{
    std::cout << "Answer: ";
    std::cout << x;
}
Run Code Online (Sandbox Code Playgroud)

add.h

#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED

int readNumber();
void writeAnswer(int x);

#endif // #ifndef ADD_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)

错误显示在io.cpp中.确切的错误是:

在此输入图像描述

有谁知道为什么会这样?谢谢.

编辑:我昨天用相同数量的文件(2 .cpp和1.h)做了一个小项目,我没有在另一个.cpp中包含iostream标题,它仍然编译并运行正常.

c++ io cout std member

178
推荐指数
2
解决办法
25万
查看次数

困惑的python文件模式"w +"

来自doc,

模式'r +','w +'和'a +'打开文件进行更新(注意'w +'截断文件).将"b"附加到模式以在二进制模式下打开文件,在区分二进制文件和文本文件的系统上; 在没有这种区别的系统上,添加'b'没有效果.

w +:打开文件进行书写和阅读.如果文件存在,则覆盖现有文件.如果该文件不存在,则创建一个用于读写的新文件.

但是,如何读取打开的文件w+

python io file

178
推荐指数
5
解决办法
27万
查看次数

如何确定C#/ .NET中是否存在文件?

我想在C#中测试一个包含文件路径的字符串,以确定是否存在该文件(类似于-ePerl或os.path.exists()Python中的测试).

.net c# io

173
推荐指数
4
解决办法
25万
查看次数