Answer the question
In order to leave comments, you need to log in
How to double the file size?
Help me write a file with the same bits, only to have 2 times more of them, otherwise I have already broken my head. Below is a bit by bit reading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace hdlc_ip
{
class Program
{
static void Main(string[] args)
{
FileStream file = new FileStream("C:\\2.txt",
FileMode.Open, FileAccess.Read);
byte[] buf = new byte[1024];
File.Copy("C:\\2.txt", "3.txt",true);
int r = -1;
byte b;
//StreamWriter print = new StreamWriter("C:\\2.txt", true);
//string read = File.ReadAllText("C:\\2.txt");
//print.Write(read);
while (r != 0)
{
r = file.Read(buf, 0, buf.Length);
for (int j = 0; j < r; j++)
{
b = buf[j];
for (int i = 7; i >= 0; i--)
Console.Write((b >> i) & 1);
Console.Write((j + 1) % 4 == 0 ? '\n' : ' ');
}
}
file.Close();
Console.ReadKey(true);
}
}
}
Answer the question
In order to leave comments, you need to log in
If you stupidly double the file, then like this:
class Program
{
static void Main(string[] args)
{
string filename = "C:\\1.txt";
byte[] filebytes = File.ReadAllBytes(filename);
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Write, FileShare.None))
{
fs.Seek(0, SeekOrigin.End);
fs.Write(filebytes, 0, filebytes.Length);
} // using fs
} // Main
} // class Program
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question