elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Re: Añadir numero en: 1 Marzo 2018, 16:59 pm
Me refiero añado una linea y sea 1 : linea1.
Paso un segunda línea en otro momento (otro día) y el archivo contenga:
1: linea1
2: linea2
2  Programación / Java / Añadir numero en: 1 Marzo 2018, 09:27 am
Buenos días mi caso es el siguiente, estoy trabajando con archivos, y lo que hago es pasando una url me descargo el contenido a un archivo txt.
Pero ahora necesito que cada vez que le pase una nueva url, está se copie esa dirección a otro txt y las vaya numerando.Me he quedado atascado ahí.No consigo hacerlo.
Código:
package readywrite;
import java.io.*;
import java.net.*;
public class miclase {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

//Conexión a la web
String web = "http://www.aizea.es";

FileWriter fichero=null;
try {

URL url1 = new URL(web);
URLConnection conn = url1.openConnection();

// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
                           new InputStreamReader(conn.getInputStream()));

String inputLine;

//save to this filename
String fileName = "descarga.txt";
File file = new File(fileName);

if (!file.exists()) {
file.createNewFile();
System.out.println("El archivo "+fileName + ", Creado en el directorio");
}else {
System.out.println(fileName + ", ya existe en el directorio");
}


//use FileWriter to write file
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);

while ((inputLine = br.readLine()) != null) {
bw.write(inputLine);
}

bw.close();
br.close();

System.out.println("Hecho");


}
    finally {
    if (null!=fichero) fichero.close();
    }




//mensaje a escribir

//Escritura del fichero
try {
//Escritura del fichero
FileWriter fw = new FileWriter("1.txt", true);
BufferedWriter out = new BufferedWriter(fw);
PrintWriter wr = new PrintWriter(out);
int i = 0;
wr.append(i+": "+web+"\n");
wr.close();
fw.close();


}catch (Exception e) {
System.out.println("Error"+e);
}
try {
FileReader fr = new FileReader("1.txt");
//Necesito almacenar el texto A UN BUFFER
BufferedReader bf = new BufferedReader(fr);
System.out.println(bf.readLine());

}catch(Exception e) {
System.out.println("Error"+ e);
}
}

}
Gracias
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines