How do I read a text file of about 2 GB? [duplicat

2019-01-20 23:28发布

This question already has an answer here:

I have a .txt file whose memory is more than 2 GB. The problem is I cannot open it with Notepad, Notepad++ or any other editor programs.

Any solutions?

10条回答
ら.Afraid
2楼-- · 2019-01-20 23:40

Instead of loading / reading the complete file, you could use a tool to split the text file in smaller chunks. If you're using Linux, you could just use the split command (see this stackoverflow thread). For Windows, there are several tools available like HJSplit (see this superuser thread).

查看更多
叛逆
3楼-- · 2019-01-20 23:41

WordPad will open any text file no matter the size. However, it has limited capabilities as compared to a text editor.

查看更多
小情绪 Triste *
4楼-- · 2019-01-20 23:45

If you only need to read the file, I can suggest Large Text File Viewer. https://www.portablefreeware.com/?id=693

and also refer this

Text editor to open big (giant, huge, large) text files

else if you would like to make your own tool try this . i presume that you know filestream reader in c#

const int kilobyte = 1024;
const int megabyte = 1024 * kilobyte;
const int gigabyte = 1024 * megabyte;

public void ReadAndProcessLargeFile(string theFilename, long whereToStartReading = 0)
{
    FileStream fileStream = new FileStream(theFilename, FileMode.Open, FileAccess.Read);
    using (fileStream)
    {
        byte[] buffer = new byte[gigabyte];
        fileStream.Seek(whereToStartReading, SeekOrigin.Begin);
        int bytesRead = fileStream.Read(buffer, 0, buffer.Length);
        while(bytesRead > 0)
        {
            ProcessChunk(buffer, bytesRead);
            bytesRead = fileStream.Read(buffer, 0, buffer.Length);
        }
    }
}

private void ProcessChunk(byte[] buffer, int bytesRead)
{
    // Do the processing here
}

refer this kindly

http://www.codeproject.com/Questions/543821/ReadplusBytesplusfromplusLargeplusBinaryplusfilepl

查看更多
在下西门庆
5楼-- · 2019-01-20 23:46

I always use 010 Editor to open huge files. It can handle 2 GB easily. I was manipulating files with 50 GB with 010 Editor :-)

It's commercial now, but it has a trial version.

查看更多
戒情不戒烟
6楼-- · 2019-01-20 23:52

There are quite number of tools available for viewing large files. http://download.cnet.com/Large-Text-File-Viewer/3000-2379_4-90541.html This for instance. However, I was successful with larger files viewing in Visual studio. Thought it took some time to load, it worked.

查看更多
男人必须洒脱
7楼-- · 2019-01-20 23:54

EmEditor works quite well for me. It's shareware IIRC but doesn't stop working after the license expires..

查看更多
登录 后发表回答