Java lee el contenido del archivo TXT. Se puede entender de la siguiente manera:
paquete com.campu; import java.io.bufferedInputStream; import java.io.bufferedReader; import java.io.file; import java.io.fileinputstream; import java.io.inputstreamreader; import java.io.reader; /** * @author coder Xiaojiang* H20121012.java * 2012-10-12 11:40:21 pm */public class H20121012 { /** * Function: Java reads the content of the txt file* Steps: 1: Get the file handle first* 2: Obtaining the file handle is used to input a bytecode stream, and the input stream needs to be read * 3: After reading the input stream, El flujo de byte generado debe leerse * 4: salida de una línea por una. Readline (). * Nota: Lo que debe considerarse son excepciones * @param filepath */ public static void readtxtfile (string filepath) {try {string coding = "gbk"; Archivo archivo = nuevo archivo (filepath); if (file.isfile () && file.exists ()) {// juzga si el archivo existe inputStreamReader read = new InputStreamReader (new FileInputStream (archivo), codificación); // Considere el formato de codificación BufferedReader Buffereder = new BufferedReader (Read); Cadena linetxt = null; while ((linetxt = bufferedReader.readline ())! = null) {system.out.println (linetxt); } read.close (); } else {System.out.println ("no se puede encontrar el archivo especificado"); }}} catch (Exception e) {System.out.println ("Error de lectura de contenido de archivo"); E.PrintStackTrace (); }} public static void main (string argv []) {String filePath = "l: //apache//htdocs//res//20121012.txt"; // "res/"; readTxtFile (FilePath); }}Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.