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.

Hilfe: Dateiverwaltung mit Java

Empfohlene Antworten

Veröffentlicht

Hallo Progger!

Ich muss als armer FISI Java proggen und habe keine Ahnung:

Ich bräuchte ein wenig Hilfe!

Ich soll anhand des Java-Codes herausfinden was die Befehle readInt, writeInt, seek und getFilePointer bedeuten.

Sorry Leute ich habe keine Ahnung, was bedeuten denn die Befehle und welche Befehle aus dem Sourcecode haben was mit Dateiverwaltung zu tun!

Danke für Eure Mühe, denn ich sehe nur komische Zeichen!

XXXXXXXXXXXXXXXXXXXXXXX

import java.io.*;

public class Datei1 {

public static void main(String[] args) {

try {

RandomAccessFile datei = new RandomAccessFile("c:\\test.dat", "rw");

for (int i=0; i<20; i++) {

datei.writeInt(i*10);

}

datei.seek(0);

for (int i=0; i<20; i++) {

long position;

position = datei.getFilePointer();

int zahl;

zahl = datei.readInt();

System.out.println("Position: "+position+"; Wert: "+zahl);

}

datei.close();

} catch (IOException ioe) {

ioe.printStackTrace();

}

}

}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

writeInt

Writes an int to the file as four bytes, high byte first. The write starts at the current position of the file pointer.

Schreibt also wie der Name schon sagt nen Int in die Datei.

readInt

Reads a signed 32-bit integer from this file.

Liest nen int raus

getFilePointer

Gibt einfach nen Long zurück der die aktuelle Position als Offset in der Datei anzeigt.

seek

Springt an den angegebenen Offset der Datei gezählt vom Anfang an, nicht die relative Position, wo dann das nächste mal gelesen und geschrieben wird.

Nen Blick in die API hilft...

getFilePointer():

Gibt dir zurück wo dein "cursor" grade in der Datei steht.

seek(long pos):

Setzt den "cursor" an eine von dir bestimmte Stelle

writeInt(int v):

Schreibt dein Integer mit 4 Bytes in deinen Outputsream.

readInt():

Dreht das oben genannte wieder um =)

Ahh zu langsam geguckt :D

Aber mit Dateiverwaltung hat das nix zu tun, das Teil öffnet die Datei, schreibt da 10, 20, 30 ... bis 200 rein, geht danach an den Anfang und liest die Zahlen wieder aus wobei jeweils die Cursor Position in der Datei ausgegeben wird.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.