Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# read large file

int filesize = (new FileInfo(filePath)).Length;            
using (Stream sr = File.OpenRead(filePath))
{
  int maxchunk = 1024;
    for(long x = 0; x < totalChunk; x++ )
    {
        long LefttotalLegth = filesize - (x * maxchunk);
        long leghtcopy = Math.Min(maxchunk, LefttotalLegth);
        byte[] chunkbyte = new byte[leghtcopy];        
        sr.Read(chunkbyte, 0, chunkbyte.Length);
       //Do something after read. like write to file
    }                           
}     
Comment

c# read huge file

class Program
{        
    static void Main(String[] args)
    {
        const int bufferSize = 1024;

        var sb = new StringBuilder();
        var buffer = new Char[bufferSize];
        var length = 0L;
        var totalRead = 0L;
        var count = bufferSize; 

        using (var sr = new StreamReader(@"C:Tempfile.txt"))
        {
            length = sr.BaseStream.Length;               
            while (count > 0)
            {                    
                count = sr.Read(buffer, 0, bufferSize);
                sb.Append(buffer, 0, count);
                totalRead += count;
            }                
        }

        Console.ReadKey();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# xml check if attribute exists 
Csharp :: c# list get last element 
Csharp :: c# 10 null checl 
Csharp :: web.config customerrors not working 
Csharp :: self referencing loop detected for property entity framework 
Csharp :: console writeline 
Csharp :: autoit console write 
Csharp :: how create two database conction in laravel 
Csharp :: selenum wait for element c# 
Csharp :: c# sbyte 
Csharp :: how to jump in unity using physics 
Csharp :: except method c# 
Csharp :: how to empty an array c# 
Csharp :: C# [] overload 
Csharp :: list c# 
Csharp :: csv to xml using xmldocument c# 
Csharp :: using statement c# 
Csharp :: static keyword 
Csharp :: c# out argument 
Csharp :: add rotation 
Csharp :: unity image button 
Csharp :: if session is not active then redirect to login page mvc.net 
Csharp :: c# insert today datetime 
Csharp :: Bedingungen in C# – if, else und else if 
Csharp :: mvc form name 
Csharp :: c# pull request 
Csharp :: c# Unit Test IDbContextFactory 
Csharp :: Include multiple siblings at the Level 
Csharp :: control shot c# WF 
Csharp :: wpf loop through grid rows 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =