Click here to Skip to main content
15,884,099 members
Home / Discussions / C#
   

C#

 
JokeRe: Buffered Stream & OpenRead Pin
Richard Deeming7-Jul-14 9:27
mveRichard Deeming7-Jul-14 9:27 
GeneralRe: Buffered Stream & OpenRead Pin
Kornfeld Eliyahu Peter7-Jul-14 9:31
professionalKornfeld Eliyahu Peter7-Jul-14 9:31 
GeneralRe: Buffered Stream & OpenRead Pin
computerpublic7-Jul-14 9:29
computerpublic7-Jul-14 9:29 
GeneralRe: Buffered Stream & OpenRead Pin
Richard Deeming7-Jul-14 9:39
mveRichard Deeming7-Jul-14 9:39 
GeneralRe: Buffered Stream & OpenRead Pin
OriginalGriff7-Jul-14 9:35
mveOriginalGriff7-Jul-14 9:35 
GeneralRe: Buffered Stream & OpenRead Pin
Eddy Vluggen7-Jul-14 10:32
professionalEddy Vluggen7-Jul-14 10:32 
GeneralRe: Buffered Stream & OpenRead Pin
computerpublic7-Jul-14 9:00
computerpublic7-Jul-14 9:00 
AnswerRe: Buffered Stream & OpenRead Pin
Richard Deeming7-Jul-14 9:08
mveRichard Deeming7-Jul-14 9:08 
computerpublic wrote:
string temPath = Path.GetTempFileName();

From the MSDN documentation:

Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

You have created an empty file; when you try to read it, you won't get any bytes returned, because it's empty.

computerpublic wrote:
Console.WriteLine("{0}={1}",arry[count],buffer[count]);//THE VISUAL PRESENTATION DOES NOT WORK

As you've written it, the code would print out "NUMBER=NUMBER" for each byte in the input file. Since there are no bytes in the input file, it won't have anything to display.


computerpublic wrote:
string filePath2 = Path.Combine("C:\\check", Path.GetFileName(filePath)); //THE OUTPUT FILE DOES NOT WORK
output.Write(buffer, 0, bytesRead);

Apart from the fact that the input file is empty, your code suggests that you're trying to write to a file in the directory C:\check, but you're actually writing to another temporary file, which will be in the %TEMP% folder.


computerpublic wrote:
turn each byte into a number and SHOW IT, turn the number back to a byte and SHOW IT

A byte is a number. It's a number between 0 and 255. There's no need to turn it into a number.

Saying "I need to turn this byte into a number" is like saying "I need to turn this fluid into a liquid". There's no conversion needed.

What I suspect you want to do is display the byte in different number bases - for example, in binary (base 2) and decimal (base 10). That's just about formatting the number, not converting it to a different type.



Based on your description, the following code should do what you're after:

using System;
using System.IO;

namespace Applica
{
    static class Program
    {
        DirectoryInfo da = new DirectoryInfo("C:\\Folder1");
        if (!da.Exists)
        {
            Console.WriteLine("The folder '{0}' does not exist.", da.FullName);
            return;
        }
        
        FileInfo[] Arr = da.GetFiles();
        if (Arr.Length == 0)
        {
            Console.WriteLine("There are no files in the folder '{0}'.", da.FullName);
            return;
        }
        
        FileInfo ap = Arr[Arr.Length - 1];
        long Totbyte = ap.Length;
        string filePath = ap.FullName;
        Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
        
        const int BufferSize = 1024;
        byte[] buffer = new byte[BufferSize];
        
        string destinationPath = Path.Combine("C:\\check", Path.GetFileName(filePath));
        
        using (Stream input = File.OpenRead(filePath))
        using (Stream output = File.OpenWrite(destinationPath))
        {
            int bytesRead;
            while ((bytesRead = input.Read(buffer, 0, BufferSize)) > 0)
            {
                for (int count = 0; count < bytesRead; count++)
                {
                    byte theByte = buffer[count];
                    string theByteInBinary = Convert.ToString(theByte, 2).PadLeft(8, '0');
                    Console.WriteLine("{0} = {1}", theByteInBinary, theByte);
                }
                
                output.Write(buffer, 0, bytesRead);
            }
        }
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


AnswerRe: Buffered Stream & OpenRead Pin
Paulo Zemek7-Jul-14 11:18
mvaPaulo Zemek7-Jul-14 11:18 
QuestionPop up error message when I call AS400 Stored Procedures via c# application Pin
JanakaND7-Jul-14 0:43
JanakaND7-Jul-14 0:43 
AnswerRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
Pete O'Hanlon7-Jul-14 0:52
mvePete O'Hanlon7-Jul-14 0:52 
GeneralRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
JanakaND7-Jul-14 1:11
JanakaND7-Jul-14 1:11 
AnswerRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
Kornfeld Eliyahu Peter7-Jul-14 1:36
professionalKornfeld Eliyahu Peter7-Jul-14 1:36 
GeneralRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
Pete O'Hanlon7-Jul-14 2:17
mvePete O'Hanlon7-Jul-14 2:17 
GeneralRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
Bernhard Hiller7-Jul-14 2:52
Bernhard Hiller7-Jul-14 2:52 
GeneralRe: Pop up error message when I call AS400 Stored Procedures via c# application Pin
JanakaND7-Jul-14 16:59
JanakaND7-Jul-14 16:59 
QuestionJoin Table with Data table Pin
Mohammad Soleimani6-Jul-14 23:10
Mohammad Soleimani6-Jul-14 23:10 
AnswerRe: Join Table with Data table Pin
Eddy Vluggen7-Jul-14 0:19
professionalEddy Vluggen7-Jul-14 0:19 
GeneralRe: Join Table with Data table Pin
Mohammad Soleimani7-Jul-14 1:27
Mohammad Soleimani7-Jul-14 1:27 
QuestionRe: Join Table with Data table Pin
Eddy Vluggen7-Jul-14 7:13
professionalEddy Vluggen7-Jul-14 7:13 
AnswerRe: Join Table with Data table Pin
Mohammad Soleimani7-Jul-14 7:59
Mohammad Soleimani7-Jul-14 7:59 
GeneralRe: Join Table with Data table Pin
Eddy Vluggen7-Jul-14 8:49
professionalEddy Vluggen7-Jul-14 8:49 
GeneralRe: Join Table with Data table Pin
Mohammad Soleimani7-Jul-14 16:46
Mohammad Soleimani7-Jul-14 16:46 
QuestionChainedFilter.cs is not available in Lucene.Net 3.0.3? Pin
Shubhanshu Pathak6-Jul-14 18:16
Shubhanshu Pathak6-Jul-14 18:16 
AnswerRe: ChainedFilter.cs is not available in Lucene.Net 3.0.3? Pin
Dave Kreskowiak6-Jul-14 18:21
mveDave Kreskowiak6-Jul-14 18:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.