Autor Beitrag
Skiller-1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 10:03 
Ich versuche ein Programm zu schreiben, wo ich den Pfad einer Datei belibigenformates angeben kann und mir dann daraufhinn in einer Textbox der Datenstrom angezeigt wird. Der Datenstrom sollte in Hexadezimal oder Binärformat sein.

Ich habe jetzt schon unzählige versuche mit den Streamread, Stream, Filestream, Binaryreader durch komme aber zu keinen Ergebniss.

Hat jemand eine Idee?
lothi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 114
Erhaltene Danke: 3



BeitragVerfasst: Do 21.08.08 10:06 
Hallo

Einer hast du noch vergessen:

MemoryStream

Gruss Lothi
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 10:13 
Ja den habe ich bewusst rausgelassen in meiner Aufzählung, weil ich denke das der doch eigentlich nur für Datenströme zwischen Arbeitspeicher und Programm zuständig ist und ich ja die "Datenströme" von Datein haben will die auf einer Festplatte gepeichert sind.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 21.08.08 11:05 
Hallo!

Der FileStream ist schon richtig. Wie sah denn Dein Versuch da aus und wo hat's nicht geklappt?

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 12:00 
Naja das ganze funktioniert schon soweit ich das getestet habe mit textdatein aber mit anderen Datein funktioniert das noch nicht so gut. :(

Weil das ja eigentlich alles bytzahlen sind und nicht die Binäre bzw. Hexadezimale darstellung des Filestreams. (ich weis das man das auch umrechnen kann)
Ich möchte viel ehre die unveränderte darstellung des Filestreams.

Das habe ich momentan:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
FileStream fs = new FileStream(textBox2.Text, FileMode.Open, FileAccess.Read);
            FileInfo fi = new FileInfo(textBox2.Text);
            byte[] arrbyte = new byte[fi.Length];

            fs.Read(arrbyte, 0, Convert.ToInt32(fi.Length));

            for (int i = 0; i < fi.Length; i++)
            {
                textBox1.Text += arrbyte[i] + " ";
            }
            fs.Close();


Moderiert von user profile iconChristian S.: I- durch C#-Tags ersetzt
lothi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 114
Erhaltene Danke: 3



BeitragVerfasst: Do 21.08.08 12:07 
Hallo Skiller

Empfehlung Nr. 1 nimm den StringBuilder zum verknüpfen des Textes. fi kann ziemlich gross werde.

Dann nimmst du sb.AppendFormat("{0:X2}",arrbyte[i]);
dann
textbox1.Text = sb.ToString();

Wenn du mit grossen Datenmengen zu tun hast nimm BeginRead so wird das ganze Asynchron ausgeführt.

Gruss Lothi
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 21.08.08 12:09 
Zusätzlich zu dem was lothi schrieb:

(1) Benutze die using-Anweisung. Außerdem kannst Du das Öffnen auch kürzer haben:
ausblenden C#-Quelltext
1:
2:
3:
4:
using(FileStream fs = File.OpenRead(textBox2.Text))
{
/* ... alles andere ... */
}

Das fs.Close() kannst Du Dir dann sparen.

(2) Du brauchst keine FileInfo um die Länge des Streams zu kennen. Ein FileStream hat selber eine Length-Eigenschaft.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".


Zuletzt bearbeitet von Christian S. am Do 21.08.08 12:10, insgesamt 1-mal bearbeitet
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 12:10 
Ja danke für die tollen tipps, allerdings geht es mir hier nicht um Performance, ich kenne die sachen die du genannt hast auch bereits wichtiger wäre erstmal eine Lösung meines Problems. (was nicht heißen sll das ich nicht dankbar für die Tipps wäre)
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 21.08.08 12:12 
user profile iconSkiller-1988 hat folgendes geschrieben:
Ja danke für die tollen tipps, allerdings geht es mir hier nicht um Performance, ich kenne die sachen die du genannt hast auch bereits wichtiger wäre erstmal eine Lösung meines Problems.(was nicht heißen sll das ich nicht dankbar für die Tipps wäre)
Die Lösung steht in Lothis Posting!

user profile iconlothi hat folgendes geschrieben:
Dann nimmst du sb.AppendFormat("{0:X2}",arrbyte[i]);

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 12:20 
Ok die sachen sind mir zwar bekannt aber ich habe in dem Fall nicht auf die Performance Wertgelegt da es zunächst nur ein Test ist. Trozdem danke für eure Tipps habe es jetzt auch geändert.
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 12:22 
OK dann bedanke ich mich erstmal für die schnelle hilfe.
lothi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 114
Erhaltene Danke: 3



BeitragVerfasst: Do 21.08.08 12:36 
Geht auch so:


ausblenden C#-Quelltext
1:
textBox1.Text += String.Format(" {0:X2} ",arrbyte[i]);					


//edit: Klammer vergessen

Gruss Lothi
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 21.08.08 12:43 
Oder:
ausblenden C#-Quelltext
1:
textBox1.Text += arrbyte[i].ToString("X2");					

;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
lothi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 114
Erhaltene Danke: 3



BeitragVerfasst: Do 21.08.08 13:29 
Richtig Christian und das alles ohne das der Code optimiert wurde. :lol: 8)
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Do 21.08.08 15:24 
habe doch noch eine frage gibt es auch ein formatierungszeichen für das Binär Format? (so wie das X für Hexadezimale ausgabe steht)
lothi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 114
Erhaltene Danke: 3



BeitragVerfasst: Do 21.08.08 15:35 
Hallo

probier mal:

Convert.ToString(deineZahl, 2);

Wobei DeineZahl eine Dezimal Zahl sein sollte.

Gruss Lothi;
Skiller-1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 100

Win XP | Debian | Ubuntu
C# | PHP | VB.NET
BeitragVerfasst: Fr 22.08.08 07:02 
Ok es fuktioniert danke nochmal. :D