{"id":693,"date":"2024-03-06T17:51:23","date_gmt":"2024-03-06T17:51:23","guid":{"rendered":"https:\/\/javigomez.org\/?p=693"},"modified":"2025-09-29T20:33:15","modified_gmt":"2025-09-29T20:33:15","slug":"u11-06-lectura-de-archivo-de-texto-linea","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2024\/03\/06\/u11-06-lectura-de-archivo-de-texto-linea\/","title":{"rendered":"U11-06-Lectura de archivo de texto (l\u00ednea)"},"content":{"rendered":"\n<p>En Java, BufferedReader y readLine() son dos elementos com\u00fanmente utilizados para leer datos de texto de forma eficiente, especialmente cuando se trabaja con archivos. <\/p>\n\n\n\n<p><strong>BufferedReader<\/strong>: Es una clase que ofrece una lectura de texto m\u00e1s eficiente que la clase FileReader al utilizar un buffer interno. Esto significa que, en lugar de leer un car\u00e1cter a la vez, lee bloques m\u00e1s grandes de datos a la memoria, lo que reduce las llamadas al sistema operativo y mejora el rendimiento. <\/p>\n\n\n\n<p><strong>readLine<\/strong>(): Es un m\u00e9todo de la clase BufferedReader que se utiliza para leer una l\u00ednea de texto desde el archivo. La l\u00ednea le\u00edda incluye el salto de l\u00ednea (\\n o \\r\\n) al final de la misma. Devuelve la l\u00ednea le\u00edda como un String o null si se ha llegado al final del archivo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\n\npublic class A01006 {\n\n\tpublic static void main(String&#91;] args) {\n\t\t\n\tBufferedReader in=null;\n\t\n\ttry {\n\t\tin=new BufferedReader(new FileReader(\"src\\\\U11\\\\a.txt\"));\n\t\tString linea = in.readLine();\n\t\twhile (linea!=null) {\n\t\t\tSystem.out.println(linea);\n\t\t\tlinea = in.readLine();\n\t\t}\n\t} catch (IOException e) {\n\t\tSystem.out.println(e);\n\t}finally {\n\t\ttry {\n\t\t\tin.close();\n\t\t} catch (IOException e) {\n\t\t\tSystem.out.println(e);\n\t\t}\n\t}\n\n\t}\n\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Java U11 06 Lectura archivo linea\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/EUeqazJ9bds?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>En Java, BufferedReader y readLine() son dos elementos com\u00fanmente utilizados para leer datos de texto de forma eficiente, especialmente cuando se trabaja con archivos. BufferedReader: &hellip; <\/p>\n","protected":false},"author":1,"featured_media":694,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[61,146,203,282],"class_list":["post-693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-bufferedreader","tag-filereader","tag-java","tag-readline"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=693"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/693\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/693\/revisions\/873"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/694"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}