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: FileInputSteam

Empfohlene Antworten

Veröffentlicht

Guten Morgen,

ich programmiere zur Zeit an einem FTPClient und dazu nehme ich diese Library (org.apache.commons.net.ftp.FTPClient). Es funktioniert auch soweit der down und upload jedoch werden beim Upload ( den ich unten als Code angefügt habe ) die Files größer und so werden zum Beispiel jpg's nicht korrekt angezeigt nach dem Upload, gif's können nicht mehr gelesen werden und von mp3's bleiben nur noch vereizelte Tonspuren übrig.

Wie müsste ich den Code abändern damit der Upload korrekt funktioniert ?

Schonmal danke im Vorraus.


public class UploadListener implements ActionListener {


	private FTPClient client;


	public UploadListener(FTPClient client) {

		this.client = client;


	}


	@Override

	public void actionPerformed(ActionEvent e) {


		JFrame frame = new JFrame();

		String filePath;

		String fileName;


		JFileChooser dateiAuswahl = new JFileChooser();

		dateiAuswahl.showOpenDialog(frame);

		filePath = dateiAuswahl.getSelectedFile().getPath();


		// Test von FilePath

		System.out.println("Filepath: " + filePath);


		fileName = dateiAuswahl.getSelectedFile().getName();

		// Test vom Outputnamen

		System.out.println(fileName);


		FileInputStream fis = null;

		BufferedInputStream bis = null;

		try {

			fis = new FileInputStream(filePath);

			bis = new BufferedInputStream(fis);

			client.storeFile(fileName, bis);

			bis.close();

			fis.close();

		} catch (FileNotFoundException e1) {

			System.out.println("FILE NOT FOUND!");

			e1.printStackTrace();

		} catch (IOException e1) {

			System.out.println("IOException!");

			e1.printStackTrace();

		}


	}


}

Hier hab ich zum Beispiel ein .jpg um zu demonstrieren was ich meine.

Bild - original

lolgy.jpg

Bild - nach upload

lol2q.jpg

Servus,

kann es sein, dass der Dateityp nicht stimmt? Du also ein binäres File hochlädst, der Client aber meint, es wäre ein Textfile? Die Methode setFileType könnte hier helfen.

Peter

  • Autor

Morgen ;),

Ich hab jetzt das ein oder andere probiert aber die setFileType Methode kann ich weder auf den Stream noch auf eine File anwenden wenn ich zum beispiel noch deine File einfüge wie:

File toUpload = new File (filePath);

Gegoogelt hab ich das ganze auch schon aber leider nix gefunden, wäre nett wenn ihr mir nochmals helfen könntet.

lg Christoph

Hi,

ich denke Du brauchst noch eine Instanz von einer Klasse Namens "InputStreamReader". Ebenfalls findest Du diese Klasseim java.io-Package.

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.