81
C, C++, C#, Java, Visual Basic, HTML, PHP, CSS, Javascript, Ajax, Joomla, MySql y más / Re:Leer archivo txt de un servidor remoto android studio (txt alojado en dropbox)
« en: 27 de Junio 2015, 12:09 »
Hola a todos con este código he logrado leer el fichero de texto puesto de ejemplo por Ogramar (he utilizado java 8 ):
Saludos!
Código: [Seleccionar]
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.io.IOException;
public class Ejemplo1{
public static void main(String[]args){
System.out.println("Resultado: "+leerFicheroUrl());
}
public static String leerFicheroUrl() {
String str1="";
String str2="";
try {
// Create a URL for the desired page
URL url = new URL("https://projecteuler.net/project/resources/p022_names.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str1 = in.readLine()) != null) {
str2 = str2 + str1;
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return str2;
}
}
Saludos!