Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

In der folgenden Funktion kopiere ich eine Datei von einem, per USB verbundenen PDA, das dauert allerdings bei Dateien über 50 kb ewig lange.

Jemand eine Idee, wie ich es ein wenig optimieren kann?

        private void CeCopyFile(CeFileInfo sourceFileInfo, String sDest)
{
int i;
CeFileStream cStream;
System.IO.FileStream fout;

try
{
try
{
cStream = sourceFileInfo.Open(CeFileAccess.Read, CeFileMode.OpenExisting, CeShareMode.Read);
}
catch (System.IO.FileNotFoundException exc)
{
MessageBox.Show(exc.Message);
return;
}
try
{
fout = new System.IO.FileStream(sDest, System.IO.FileMode.Create);
}
catch (System.IO.IOException exc)
{
MessageBox.Show(exc.Message);
return;
}
}
catch (IndexOutOfRangeException exc)
{
MessageBox.Show(exc.Message);
return;
}


try
{
do
{
i = cStream.ReadByte();
if (i != -1) fout.WriteByte((byte)i);
} while (i != -1);
}
catch (System.IO.IOException exc)
{
MessageBox.Show(exc.Message);
}

cStream.Close();
fout.Close();
}
}[/PHP]

Like this...?!

        private void CeCopyFile(CeFileInfo sourceFileInfo, String sDest)
{
CeFileStream cStream;
System.IO.FileStream fout;

try
{
try
{
cStream = sourceFileInfo.Open(CeFileAccess.Read, CeFileMode.OpenExisting, CeShareMode.Read);
}
catch (System.IO.FileNotFoundException exc)
{
MessageBox.Show(exc.Message);
return;
}
try
{
fout = new System.IO.FileStream(sDest, System.IO.FileMode.Create);
}
catch (System.IO.IOException exc)
{
MessageBox.Show(exc.Message);
return;
}
}
catch (IndexOutOfRangeException exc)
{
MessageBox.Show(exc.Message);
return;
}


try
{
byte[] buffer = new byte[cStream.Length];
int length = (int)cStream.Length;
int sum=0;
int count;

while ((count = cStream.Read(buffer, sum, length - sum)) > 0)
sum += count;

fout.Write(buffer, 0, (int)cStream.Length);
}
catch (System.IO.IOException exc)
{
MessageBox.Show(exc.Message);
}

cStream.Close();
fout.Close();
}
}[/PHP]

Jein. Ich würde mit einem festen Puffer arbeiten. Nicht das mal auf dem portablen Gerät eine Datei >50MB ist :D

Also im try-Body:

byte[] buffer = new byte[1024];

int count;

while ((count = cStream.Read(buffer, 0, buffer.Length)) > 0)

	fout.Write(buffer, 0, count);

Jein. Ich würde mit einem festen Puffer arbeiten. Nicht das mal auf dem portablen Gerät eine Datei >50MB ist

Das halte ich für keine gute Idee, dabei geht es um eine Inventurdatenverwaltung, und falls da wirklich mal der Fall eintreten sollte, das eine Datei über 50 MB sein sollte, darf sie auf gar keinen Fall übergangen werden, stell dir das Chaos vor, wenn da irgendwas fehlt ;)

Hmm, ich verstehe den Zusammenhang nicht.

Wo werden denn Dateien übergangen oder fehlen? Der Puffer von 1 kB hat nix damit zu tun. Dein Beispiel was zu langsam war, hatte einen "Puffer" von einem Byte. Jetzt halt von 1024. Die Größe des Puffers kann sehr wohl auf die jeweilige Situation optimiert werden.

Aber an dem Verfahren ändert, dass Du liest nacheinander jeweils 1024 byte aus Deiner CE-Datei liest und diese Bytes in die Zieldatei schreibst, ändert das nichts.

Ob Du nun alle Daten auf einmal in den Puffer liest und auf einmal in die Zieldatei schreibst oder Häppchenweise ist völlig egal.

Sobald ein Fehler passiert, kommt eh die Exception.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.