标签: readfile

按设备/ inode顺序读取文件?

我对读取磁盘上的大量文件的有效方法感兴趣.我想知道我是否按设备对文件进行排序,然后通过inode我会对自然文件读取速度有所提高.

performance readfile

3
推荐指数
1
解决办法
1123
查看次数

C++参数在运行时发生变化

我有一个非常简单的函数,它应该读取一个txt文件并通过一个类型字符串向量返回所有行.我已经使用调试器对它进行了几次调试,我唯一注意到的是"fileName"的值在ifstream声明的行上发生了变化.我究竟做错了什么??谢谢.

vector<string> readFile(char* fileName)
{
    vector<string> fileLines;
    fileLines.clear();
    string line;
    ifstream myfile (fileName);
    if (myfile.is_open())
    {
        while ( myfile.good() )
        {
            getline (myfile,line);
            fileLines.push_back(line);
        }
        myfile.close();
    }
    return fileLines;
}
Run Code Online (Sandbox Code Playgroud)

//////////////////////////////////

我有这个函数应该返回当前目录中所有txt文件的文件名.

   vector<char*> getFileList()
    {
        vector<char*> fileNames;
        fileNames.clear();
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind = INVALID_HANDLE_VALUE;
        char currentPath[_MAX_PATH];
        getCurrentPath(currentPath);
        strncat(currentPath, "\\*", 3);
        if (hFind = FindFirstFile(currentPath, &FindFileData))
        {

            string fileExtension = getExt(FindFileData.cFileName);
            if (fileExtension == "txt" || fileExtension == "TXT")
            {
                fileNames.push_back(FindFileData.cFileName);
            }
            while(FindNextFile(hFind, &FindFileData) != 0)
            {
                string fileExtension = getExt(FindFileData.cFileName); …
Run Code Online (Sandbox Code Playgroud)

c++ arguments readfile

3
推荐指数
1
解决办法
167
查看次数

Python文件的Python读取应该在Windows 7之前停止

我使用Python打开计算机中的物理磁盘来读取第一个扇区.

disk = r"\\.\PhysicalDrive0"
with open(disk, 'r') as f:
        f.seek(0)
        partdata = f.read(512)
len(partdata)
Run Code Online (Sandbox Code Playgroud)

在Windows XP len(partdata)中将返回512并具有正确的内容.在Windows 7中len(partdata)返回230并且数据是正确的,直到它中断.

此外,尝试进入磁盘更远不起作用,它只返回前230个字节.

Python版本2.7.1和2.7.2 32位和64位

在Windows 7上,一台32位机器一台64位.

python disk windows-7 readfile

3
推荐指数
1
解决办法
619
查看次数

PHP fgetcsv()分隔符

关于fgetcsv()文档,函数内部有一些参数fgetcsv():句柄,长度,分隔符,外壳和转义.

现在,我有两个问题:

  1. 外壳究竟做了什么?
  2. 我有一个csv文件,每行5列.想象一下这样的事情:1,2,3,4,5

因此索引从0到4.但是每当我想从索引4获取日期时,返回一个空值.除非我在它之后放一个逗号(通过在它之后填充一个额外的列,使得内容如下:1,2,3,4,5,6).我该如何解决这个问题?由于在csv文件的每一行中的最后一项之后缺少逗号,似乎存在一些问题!

php csv readfile fgetcsv

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

在readFile之后使用行

我正在尝试在Haskell中进行一些编程.我正在尝试读取一个文件,然后使用line函数将文件中的每一行放在一个列表中.这是部分代码:

file = "muh.rtr"
readTrack :: String -> Track
readTrack file =
    do      let defFile = readFile file
            let fileLines = lines defFile
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到此错误:

Parser.hs:22:39:
    Couldn't match expected type `String' with actual type `IO String'
    In the first argument of `lines', namely `defFile'
    In the expression: lines defFile
    In an equation for `fileLines': fileLines = lines defFile
Run Code Online (Sandbox Code Playgroud)

我一直在互联网上搜索几个小时,希望能在某处找到答案,但到目前为止我还没那么幸运.

haskell lines readfile

3
推荐指数
3
解决办法
3541
查看次数

如何使用poi jar读取java api中的docx文件内容

我已经阅读了doc文件,现在我正在尝试阅读docx文件内容.当我搜索样本代码时,我发现很多,没有任何效果.检查代码以供参考......

import java.io.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;

public class createPdfForDocx {

public static void main(String[] args) {
InputStream fs = null;  
    Document document = new Document();
    XWPFWordExtractor extractor = null ;

try {

    fs = new FileInputStream("C:\\DATASTORE\\test.docx");
    //XWPFDocument hdoc=new XWPFDocument(fs);
    XWPFDocument hdoc=new XWPFDocument(OPCPackage.open(fs));
    //XWPFDocument hdoc=new XWPFDocument(fs);
    extractor = new XWPFWordExtractor(hdoc);
    OutputStream fileOutput = new FileOutputStream(new       File("C:/DATASTORE/test.pdf"));
    PdfWriter.getInstance(document, fileOutput);
    document.open();
    String fileData=extractor.getText();
    System.out.println(fileData);
    document.add(new Paragraph(fileData));
    System.out.println(" pdf document created");
        } catch(IOException e) {
            System.out.println("IO Exception"); …
Run Code Online (Sandbox Code Playgroud)

java docx apache-poi readfile

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

TStringList.LoadFromFile - 大文本文件的例外

我正在运行Delphi RAD Studio XE2.

我有一些非常大的文件,每个文件都包含大量的行.线条本身很小 - 只有3个标签分隔的双打.我想将文件加载到TStringList使用中,TStringList.LoadFromFile但这会引发大文件的异常.

对于200万行(约1GB)的文件,我得到了EIntOverflow例外.对于较大的文件(例如,2000万行和大约10GB),我得到了ERangeCheck例外.

我有32GB的RAM可供使用,我只是想加载这个文件并快速使用它.这里发生了什么,我有什么其他选择?我可以使用带有大缓冲区的文件流将此文件加载到TStringList中吗?如果是这样,请举一个例子.

delphi tstringlist filestream readfile delphi-xe2

3
推荐指数
1
解决办法
5215
查看次数

同时从文件中写入和读取

我一直试图同时从文件中读取和写入,并且我试图将text.txt内容中的所有选项卡替换为空格.这是我的代码:

int main()
{
   FILE* filePtr = fopen("text.txt", "w+");

   char c;
   c = fgetc(filePtr);
   fpos_t num;
   while(c != EOF)
   {
       if(c == '\t')
       {
           fgetpos(filePtr, &num);
           num--;
           fsetpos(filePtr, &num);
           fputc(' ', filePtr);
       }
       c = fgetc(filePtr);
   }
}
Run Code Online (Sandbox Code Playgroud)

text.txt的内容如下:

嗨\ t我的名字\ t是\ t杰克!

当我运行此代码时,text.txt文件中的输出只是空格.那里没有人物.我该怎么做才能让替换按预期进行?

c file writefile readfile

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

如何逐行读取文件并在Scala中关闭它?

通常,他们会告诉你

import scala.io.Source
for(line <- Source.fromPath("myfile.txt").getLines())
  println(line)
Run Code Online (Sandbox Code Playgroud)

这似乎让文件保持打开状态.什么是可以接近的对手?

scala readfile line-by-line

3
推荐指数
1
解决办法
6566
查看次数

Haskell无法正确解析文本

在测试文件中,我有以下测试字符串:

?? Test?
Run Code Online (Sandbox Code Playgroud)

我尝试使用和不使用BOM的UTF-8编码文件,并使用UCS-2.我已经尝试将Haskell的编码设置为UTF-8.

文本总是出现(或更糟):

"\8745\9559\9488\920\226\191\920\237\8359 Test\960\199\232" 
Run Code Online (Sandbox Code Playgroud)

每当我键入打印"?" 的代码"\12298",而不是\960\199\232从FILEREAD所见.

这种行为的解决方案?

encoding haskell readfile

3
推荐指数
1
解决办法
141
查看次数