I wrote this small test class to connect to an FTP server.
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class FTPTest {
public static void main(String[] args) {
URL url = null;
try {
url = new URL("ftp://anonymous:Password@127.0.0.1");
} catch (MalformedURLException e) {
e.printStackTrace();
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
InputStream in = null;
try {
in = conn.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
BufferedInputStream bin = new BufferedInputStream(in);
int b;
try {
while ((b = bin.read()) != -1) {
char c = (char) b;
System.out.print("" + (char) b);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Here's the conclusion:
-rw-r--r-- 1 ftp ftp 4700 Apr 30 2007 premier.java
-rw-r--r-- 1 ftp ftp 88576 Oct 23 2007 Serie1_1.doc
-rw-r--r-- 1 ftp ftp 1401 Nov 21 2006 tp20061121.txt
drwxr-xr-x 1 ftp ftp 0 Apr 23 20:04 répertoire
Note the directory name at the end of the list. Must be "é" (e with a sharp accent) instead of the double character "Ã ©".
This reminds me of a problem I had with JSF when a stir occurred between the standards. I have little experience coding characters, although I'm not sure what is going on. I assume the server output is in ASCII, so how can I adapt the output so that it displays correctly in the console?
source
share