Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it L'avatar di Lanus
    Registrato dal
    Apr 2006
    Messaggi
    43

    [C#] Eccezione di PeekChar()

    In questa porzione di codice

    Codice PHP:
    if ( File.Exists"file.file" ) )
    {
        
    FileStream stream 
     new 
    FileStream"file.file"FileMode.OpenFileAccess.ReadFileShare.Read );
        
    BinaryReader reader = new BinaryReaderstream );

        
    int index 0;

        while ( 
    reader.PeekChar() != -1)
        {
            
    // Read data. Data stored in the file is the key
            // The index of the key is the value
            
    int key reader.ReadInt32();

            
    m_Arraykey ] = index++;
        }

        
    stream.Close();

    Mi da questo errore la funzione PeekChar().


    Codice PHP:
    System.ArgumentExceptionBuffer dei caratteri di output troppo piccolo per contenere i caratteri decodificatiCodifica 'Unicode (UTF-8)'fallback 'System.Text.DecoderReplacementFallback'.
    Nome parametrochars
       in System
    .Text.Encoding.ThrowCharsOverflow()
       
    in System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoderBoolean nothingDecoded)
       
    in System.Text.UTF8Encoding.GetChars(BytebytesInt32 byteCountCharcharsInt32 charCountDecoderNLS baseDecoder)
       
    in System.Text.DecoderNLS.GetChars(BytebytesInt32 byteCountCharcharsInt32 charCountBoolean flush)
       
    in System.Text.DecoderNLS.GetChars(Byte[] bytesInt32 byteIndexInt32 byteCountChar[] charsInt32 charIndexBoolean flush)
       
    in System.Text.DecoderNLS.GetChars(Byte[] bytesInt32 byteIndexInt32 byteCountChar[] charsInt32 charIndex)
       
    in System.IO.BinaryReader.InternalReadOneChar()
       
    in System.IO.BinaryReader.Read()
       
    in System.IO.BinaryReader.PeekChar() 
    Mi sapreste dire se esiste un modo alternativo di capire se si è arrivati alla fine del file?
    Grazie

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472
    Credo che l'errore stia nel fatto che tu verifichi la presenza di un carattere (di 2 byte) e poi prelevi un intero Int32, che è formato da 4 byte, quindi la seconda parte del valore potrebbe anche non esserci.

    Cosa devi fare esattamente? Cioè, qual è il tipo di dato che devi trattare in input dal file?
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it L'avatar di Lanus
    Registrato dal
    Apr 2006
    Messaggi
    43
    Devo leggere una sequenza di interi da un file fino alla fine dello stesso.
    Questo file purtroppo deve rimanere lo stesso in quanto è utilizzato anche da un'altra applicazione di cui non ho i sorgenti e quindi non posso cambiarlo. Come posso controllare se c'è l'intero successivo?

  4. #4
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472
    Forse è sufficiente mantenere le cose come stanno, ma intercettando l'eccezione.

    Vedi l'esempio fornito su MSDN per la classe.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  5. #5
    Utente di HTML.it L'avatar di Lanus
    Registrato dal
    Apr 2006
    Messaggi
    43
    Perfetto, così funge!
    Grazie mille

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.