опубликован 29-03-2001 10:16 MSK
вот так можно взять файлик с курсом доллара с сервера РосБизнесКонсалтинга:URL homeRBC = null;
DataInputStream dis = null;
String full = new String();
boolean cont2 = false;
try {
homeRBC = new URL("http://www.rbc.ru/out/801.csv");
dis = new DataInputStream(homeRBC.openStream());
String line = dis.readLine();
while(line != null) {
full += line + "\n";
line = dis.readLine();
}
cont2 = true;
} catch(IOException e) {
System.out.println("Error for connection to RBC ...");
}
if(cont2==true) {
String cbr = toUnicode(full);
}
После этого в переменной cbr будет храниться содержимое файлика 801.csv
функция toUnicode выглядит следующим образом:
public static String toUnicode(String str) throws IOException {
try {
String charset="windows-1251";
byte[] buf = new byte[str.length()];
str.getBytes(0, str.length(), buf, 0);
return new String(buf);
} catch(Exception e) {
return "Error toUnicode";
}
}
как записывать файл - сразу не вспомню, надо поискать ...