Leerzeichen in Pfad

starbuck86

Mitglied
Hallo zusammen.

Ich möchte eine Datei/Bild einlesen (Windows).
Problem:
Das Einlesen funktioniert nur, wenn im Pfad kein Leerzeichen ist, sonst kann er mir das Bild nicht anzeigen.

Java:
private String pfad;

public void paint(Graphics g)
	{
		Image splashImage = getToolkit().getImage(getPath()+"splashscreen_op.jpg");
		g.drawImage(splashImage, 0, 0, this); 
	}
	
	public String getPath() {		
		if (this.pfad != null) {
			return this.pfad;
		} else {
			String a = this.getClass().getResource(".").getFile().toString();
			String c[] = a.split("/");
			String d = "";
			for (int i=0; i<=(c.length-1); i++) {
				d += c[i]+"\\";
			}
			this.pfad = d;
			return this.pfad;
		}
	}

Hat jemand eine Idee?

Gruß
Thomas

PS: Ich benötige den absoluten Pfad!!
 
Java:
d = d.replace("%20", " ");

Ich frage mich, warum du statt der for nicht auch einfach alle Slash so mit Backslash ersetzt.
 
Öhm warum nicht einfach
Java:
 Image splashImage = getToolkit().getImage(this.getClass.getResource("splashscreen_op.jpg"));
 
die Leerzeichen im Pfad müssen gequotet werden:

Java:
public String quoteWhitespaces(String path) {
return path.replaceAll(" ", "\" \"");
}
 
Zurück