public class ReadBigTxt
    
{
        
""
        
private string m_LogPath = "";
        
public ReadBigTxt()
        
{

        }

        
public string GetFileTxt(string filename)
        
{
            
string str = "";
            
try
            
{
                IntPtr vFileHandle 
= CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FileShare.Read | FileShare.Write, IntPtr.Zero, FileMode.Open, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, IntPtr.Zero);
                
if (INVALID_HANDLE_VALUE != (int)vFileHandle)
                
{
                    IntPtr vMappingHandle 
= CreateFileMapping(
                    vFileHandle, IntPtr.Zero, PAGE_READWRITE, 
00"temp");
                    
if (vMappingHandle != IntPtr.Zero)
                    
{
                        IntPtr vHead 
= MapViewOfFile(vMappingHandle,
                        FILE_MAP_COPY 
| FILE_MAP_READ | FILE_MAP_WRITE, 00, IntPtr.Zero);
                        
if (vHead != IntPtr.Zero)
                        
{
                            
uint vSize = GetFileSize(vFileHandle, IntPtr.Zero);
                            
byte[] nb = new byte[vSize];
                            Marshal.Copy(vHead, nb, 
0, nb.Length);
                            str 
= System.Text.Encoding.GetEncoding("GB2312").GetString(nb);
                            nb 
= null;
                            UnmapViewOfFile(vHead);
                        }

                        CloseHandle(vMappingHandle);
                    }

                    CloseHandle(vFileHandle);
                }

            }

            
catch
            
{
                
return "";
            }

            
return str.Replace("\r""").Replace("\n""");

        }

    }
posted on 2008-03-28 11:46  小黑三  阅读(982)  评论(0编辑  收藏  举报