
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to truncate a file in C#?
To truncate a file in C#, use the FileStream.SetLength method.
Here is the syntax −
public override void SetLength (long value);
Here, int64 = Length of the stream
Value < current Length
If the value is less than the current length of the stream: The stream is truncated. If the current position is greater than the new length, the current position is moved to the last byte of the stream.
Value > current Length
The stream is expanded, and the current position remains the same. If the stream is expanded, the contents of the stream between the old and the new length are undefined.
The following is an example showing the code snippet −
public void Export(string path) { FileStream oStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); oStream.SetLength(Length); }
- Related Questions & Answers
- How to truncate a file in Java?
- How we can truncate a file at a given size using Python?
- C# Truncate Method
- How to truncate a string vector after a character in R?
- How to truncate a Python dictionary at a given length?
- How to truncate Key Length in Python Dictionary?
- How to download a file from a URL in C#?
- How to open a plain text file in C#?
- How to read a text file with C++?
- How to append text to a text file in C++?
- How to truncate a numerical vector to a specified number of decimal places in R?
- Truncate BigDecimal value in Java
- Truncate with condition in MySQL?
- How do I truncate tables properly in MySQL?
- C# Program to rename a file
Advertisements