gegenteil von skipBytes

  • Themenstarter Themenstarter gast
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
G

gast

Gast
Das ist auch schon die frage 🙂
Ist es auch möglich anstat ein Byte weiter zu gehen, ein byte zurückzukommen?

MfG
 
Schau dir mal die Klassen PushbackInputStream und PushbackReader an.

Hier vor allem die Methoden unread, markIsSupported, mark und reset
 
Wenn er ein RandomAccessFile: ja da gibts seek. Bei normalen Streams nicht :wink:
 
Code:
  public static void main(String[] args) throws IOException {
    String nameByteFile = "test.data";
    FileInputStream input = new FileInputStream(nameByteFile);
    DataInputStream inputStream = new DataInputStream(input);

  public static int nextByte(DataInputStream inputStream) throws IOException {
    byte b = (byte) 0xff;
    b = inputStream.readByte();
    int tagByte = b & 0xff;
    return tagByte;
  }

Diese Funktion "nextByte", geht immer ein Byte weiter.
Nun hab ichs mit euren Vorschlägen versucht, mit unread, mark, reset usw... klabt aber irgend was net.
Was müst ich noch aendern?

gruss
 
Muss ich dann im styl von:

Code:
      RandomAccessFile in = new RandomAccessFile("test.datat");
      
      long skip = -1;
      byte b = (byte) 0xff;
      b = in.seek(skip);
      tagByte = b & 0xff;
      return tagByte;

(sorry, bin total anfänger)

Oder seh ich da was falsch?
 
Was willst den machen?

Code:
RandomAccess File in = new RandomAccessFile("test.datat","r"); //für nur lesen
in.seek(position); //hüpft auf die Position am File hin 0 = am Anfang, etc

//oder

in.skipBytes(bytes); //dort kannst nur nach hinten gehen


Modis hat gesagt.:
"r" Open for reading only. Invoking any of the write methods of the resulting object will cause an IOException to be thrown.
"rw" Open for reading and writing. If the file does not already exist then an attempt will be made to create it.
"rws" Open for reading and writing, as with "rw", and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.
"rwd" Open for reading and writing, as with "rw", and also require that every update to the file's content be written synchronously to the underlying storage device.


Das was du vor hast geht gar net... willst du 1en Zeiger vor die Datei hüpfen oder was??

Wo willst überhaupt hinhüpfen?
 
Prog brauch ich um einzelne Bytes zu untersuchen, und an einer Stelle brauch ich eine Methode wo es ein Byte zurückhüpft. nur EIN Byte.
weis nicht ob das genug beschreibung ist um prob. lösbar zu machen, 🙂 ?
 
uiiiuiui, habs hinbekommen:

Code:
  public static int write(DataInputStream inputStream, int tagByte) throws IOException {

    long zahl = -1;
    tagByte = (int) inputStream.skip(zahll);

    return tagByte;

danke euch allen!
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben