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.

Problem bei Anwendung mit Arrays & mehrdimensionale Arrays

Empfohlene Antworten

Ich habe folgendes Problem ich lese hier Zeilen will aber nur 8 "Blöcke" aus dieser Zeile. Darum splitte ich die Zeile entsprechend und erstellen ein String Array mit einer Begrenzung von 8 und füge diese ein. Aber wozu kann ich das Teil auf 8 begrenzen wenn er mir trozdem mehr reinschreibt ?

So wirft er mir dann beim einfügen in das mehrdimensionale Array ein Exception weil er größer ist wie 8...

Ich muss dazu Sagen das die Zeilen unterschiedlich lang sind. Dachte das er mir bei 8 aufhört mit dem reinschreiben wenn der Array nicht größer ist. Ich weis zwar das ich nur 8 will aber eine Schleife geht schwer da ich sie auf einmal durch .split() einfüge.

Kann wer helfen?


	public static void lesenCopybookFile(){

		pfad = Test_JGui.getUrlCopybook();

		pfad = pfad.replace("\\","/");

		i = 0;

		copybook = new String[1][8];

		row_cache = new String[8];

		try {

			lese = new BufferedReader(new FileReader(pfad));

			while((row = lese.readLine()) != null) {				

				row = row.replaceAll("\\s+", ";");

				row_cache = row.split(";");

				for(int x = 0; x != row_cache.length; x++){

					copybook[i][x] = row_cache[x];	

				}

				i++;

			}

			lese.close();

		} catch (IOException e) {

			e.printStackTrace();

		}	


		for ( Object elem : copybook )

		    System.out.println( elem );


	}


986_Java_Cobol_to_XMLsrcte.jpg

Moin,

mach doch ein ArrayCopy.

Kopiere nur die ersten 8 Elemente.

Hier die Infos:

Klick!

Edit:

Würde bei dir so aussehen-> System.arraycopy(row_cache[x], 0, copybook[x] , 0, 8);

Bearbeitet von mharms

Moin,

mach doch ein ArrayCopy.

Kopiere nur die ersten 8 Elemente.

Hier die Infos:

Klick!

Edit:

Würde bei dir so aussehen-> System.arraycopy(row_cache[x], 0, copybook[x] , 0, 8);

Das zieh ich mal zurück, hab's falsch verstanden ;)

Hi,

ein weiterer Lösungsweg:

public static void lesenCopybookFile(){

		pfad = Test_JGui.getUrlCopybook();

		pfad = pfad.replace("\\","/");

		i = 0;

		copybook = new String[1][8];

		row_cache = new String[8];

		try {

			lese = new BufferedReader(new FileReader(pfad));

			while((row = lese.readLine()) != null) {				

				row = row.replaceAll("\\s+", ";");

				row_cache = row.split(";");

				for(int x = 0; x < 8; x++){ // <-- Wenn x kleiner 8 bleibt, dann geht das auch

					copybook[i][x] = row_cache[x];	

				}

				i++;

			}

			lese.close();

		} catch (IOException e) {

			e.printStackTrace();

		}	


		for ( Object elem : copybook )

		    System.out.println( elem );


	}

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.