{"id":1728,"date":"2015-06-19T17:11:00","date_gmt":"2015-06-19T22:11:00","guid":{"rendered":"http:\/\/linuxitos.com\/main\/agregar-texto-al-final-de-un-archivo-existente-desde-java\/"},"modified":"2015-06-19T17:11:00","modified_gmt":"2015-06-19T22:11:00","slug":"agregar-texto-al-final-de-un-archivo-existente-desde-java","status":"publish","type":"post","link":"https:\/\/linuxitos.com\/main\/agregar-texto-al-final-de-un-archivo-existente-desde-java\/","title":{"rendered":"Agregar texto al final de un archivo existente desde Java"},"content":{"rendered":"<p><span style=\"color: black;\">EL siguiente programa en java a\u00f1ade texto al final de un archivo de texto.<\/span><br \/><span style=\"color: black;\">El proyecto completo lo pueden descargar desde<\/span> <a href=\"https:\/\/mega.co.nz\/#!2dJnVRLQ!XULJBv5fkA7Wubnn6zNd7fPqWSbHKESQmGrtXt0zOvs\" target=\"_blank\"><span style=\"font-size: large;\"><b>aqu\u00ed<\/b><\/span><\/a><\/p>\n<p><span style=\"color: black;\">O el c\u00f3digo principal es:<\/span><\/p>\n<pre style=\"background: none no-repeat scroll 0% 0% rgb(0, 0, 0); border-radius: 3px; border: 1px solid rgb(0, 0, 0); font-family: &quot;Droid Sans Mono&quot;,Consolas,monospace; font-size: 13px; line-height: 20px; margin: 8px 15px; opacity: 0.85; padding: 9.5px; text-align: start; text-shadow: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\"><span style=\"color: white;\">public void agregarTextoAlfinal(String nombreArch){<br \/>        int i;<br \/>        try {<br \/>            FileWriter fstream = new FileWriter(nombreArch, true);<br \/>            BufferedWriter out = new BufferedWriter(fstream);<br \/>            for(i=0;i&lt;10;i++){<br \/>                out.write(\"Visita http:\/\/linuxgx.blogspot.mx\/ \"+i+\"n\");<br \/>            }<br \/>            out.close();<br \/>        } catch (IOException ex) {<br \/>            System.out.println(\"Error: \"+ex.getMessage());<br \/>        }<br \/> }<\/span><\/pre>\n<p><span style=\"color: black;\">Para crear previamente el archivo pueden usar este m\u00e9todo:<\/span><\/p>\n<pre style=\"background: none no-repeat scroll 0% 0% rgb(0, 0, 0); border-radius: 3px; border: 1px solid rgb(0, 0, 0); font-family: &quot;Droid Sans Mono&quot;,Consolas,monospace; font-size: 13px; line-height: 20px; margin: 8px 15px; opacity: 0.85; padding: 9.5px; text-align: start; text-shadow: none; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;\"><span style=\"color: white;\">public void crearArchivo(String archivo){<br \/>        FileWriter fwArchTemp;<br \/>        try {<br \/>            fwArchTemp = new FileWriter(archivo);<br \/>            BufferedWriter bwArchTemp;<br \/>            bwArchTemp = new BufferedWriter(fwArchTemp);<br \/>            try (PrintWriter wrArchTemp = new PrintWriter(bwArchTemp)) {<br \/>                wrArchTemp.print(\"Visita http:\/\/linuxgx.blogspot.mx\/n\");<br \/>                wrArchTemp.close(); \/*Cerrando archivo de escritura*\/<br \/>            }<br \/>            bwArchTemp.close(); \/*Cerrando apertura de archivo*\/<br \/>            fwArchTemp.close();<br \/>        } catch (IOException ex) {<br \/>            System.err.println(\"Error: \"+ex.getMessage());<br \/>        }<br \/>}<\/span><\/pre>\n<p><span style=\"color: black;\">Bueno, espero que les sirva de algo.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>EL siguiente programa en java a\u00f1ade texto al final de un archivo de texto.El proyecto completo lo pueden descargar desde aqu\u00ed O el c\u00f3digo principal es: public void agregarTextoAlfinal(String nombreArch){ int i; try { FileWriter fstream = new FileWriter(nombreArch, true); BufferedWriter out = new BufferedWriter(fstream); for(i=0;i&lt;10;i++){ out.write(\u00abVisita http:\/\/linuxgx.blogspot.mx\/ \u00ab+i+\u00bbn\u00bb); } out.close(); } catch (IOException ex) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1136,680,1138,554,1139,1137,446],"tags":[],"class_list":["post-1728","post","type-post","status-publish","format-standard","hentry","category-abrir-archivos","category-add-text-last-line-existing-file","category-agregar-texto-al-final-de-un-archivo-existente-en-java","category-archivos","category-archivos-en-java","category-file","category-java"],"_links":{"self":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/comments?post=1728"}],"version-history":[{"count":0,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/posts\/1728\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/media?parent=1728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/categories?post=1728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxitos.com\/main\/wp-json\/wp\/v2\/tags?post=1728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}