Click here to Skip to main content
16,016,425 members

Comments by computerpublic (Top 13 by date)

computerpublic 29-Nov-17 17:08pm View    
//No compiler error occur, but it gives me a LARGE empty output file that keeps building
//Also the program does not end.

using System;
using System.IO;
using System.Collections;
namespace Applica
{
static class Program
{
static void Main(string[] args)
{
bool tif = true;
bool[] array = new bool[8];
BitArray bytes = new BitArray(array);
const int BufferSize = 1024;
byte[] buffer = new byte[BufferSize];
FileInfo ap = new FileInfo("tempii.txt");
string filePath = ap.FullName;
string destinationPath = Path.Combine("C:\\check", Path.GetFileName(filePath));
using (Stream output = File.OpenWrite(destinationPath))
{
int amount = 1;
while (amount > 0)
{
for (int i = 0; i < 8; i++)
{
if (tif == true)
{
tif = false;
}
else if (tif == false)
{
tif = true;
}
array[i] = tif;
}
bytes.CopyTo(buffer, 0);//No compiler error occur, but it gives me a LARGE empty output file that keeps growing.
output.Write(buffer, 0, amount);//Also the program does not end.
}
}
}
}
}
computerpublic 29-Nov-17 4:41am View    
//I have modified the code as you suggested, and I am still getting the same error. Please see below.

using System;
using System.IO;
using System.Collections;
namespace Applica
{
static class Program
{
static void Main(string[] args)
{
bool tif = true;
byte[] buffer = BitConverter.GetBytes(tif);
FileInfo ap = new FileInfo("tempii.txt");
string filePath = ap.FullName;
string destinationPath = Path.Combine("C:\\check", Path.GetFileName(filePath));
using (Stream output = File.OpenWrite(destinationPath))
{
int bytes = 4;
while (bytes > 0)
{
for (int i = 1; i < 33; i++)//4 random bytes
{
if (tif == true)
{
tif = false;
}
else if (tif == false)
{
tif = true;
}
output.Write(buffer, 0, bytes);
}
}
}
}
}
}
computerpublic 28-Nov-17 19:10pm View    
I am still looking for help if anyone is kind enough to help. Thank you in advance.
computerpublic 24-Nov-17 12:43pm View    
OriginalGriff thank very much for your assistance. Can someone in this forum please assist? I don't it is being understand that nothing i do works. I have been at this for weeks. I am totally going in circles and very confused about how the syntax work. It's not for a lack of trying. I have tried so many different ways to succeed and end up with nothing.

I am using a loop with the variable "Totbyte" from the original program to control the loop that will start and terminate the process after the exact amount of bytes as been entered. I also want to use "output.Write(buffer, 0, bytesRead);" to assemble back the file. I am having two(2) problems.

1. How to correct nullified variables that as been commented out.
2. How to enter the new byte with respect to "output.Write(buffer, 0, bytesRead);"
computerpublic 23-Nov-17 15:27pm View    
Please let me first say that I am here looking for help. Once i comment out "using (Stream input = File.OpenRead(filePath))", it nullifies other variables which are dependent to the line being commented out. So what I end up with, are other variables which also need to be commenting out and the problem snow ball in other problems. All I want to do is have someone show me how to redo the structure where i am still doing "output.Write(buffer, 0, bytesRead);", but taking the input manually one byte of a time (assume that i have them all the bytes written down on a piece of paper). I no longer want to do the "Read in from file" to get the bytes, but I want to build back the file from all the bytes entered. I am not a professional programmer like the people in this forum. I know my screen cannot be seen, but the entire code is here to be ran. It's only a few short line of code. I do not understand how to fix this problem. If you genuinely know how to fix this problem, please help me. Thank you.