Arquivos de texto geral
Vamos pegar o arquivo de log.log como exemplo:
importar java.io.bufferedReader; importar java.io.file; importar java.io.fileInputStream; importar java.io.filenotfoundException; importar java.io.fileReader; importar java.io.ioException; public class file_test {/** * @param args */public static void main (string [] args) {arquivo file = new File ("d: //logserrRormsg.log"); if (file.exists ()) {System.out.println ("Este arquivo existe"); } else {System.out.println ("Este arquivo não existe"); } tente {fileReader fr = new FileReader (arquivo); BufferErader BR = new BufferredReader (FR); Strings s; while ((s = B.ReadLine ())! = null) {System.out.println (s); } System.out.println ("O tamanho do arquivo é (MB):" +novo FileInputStream (FILE) .AVALEBLE () / 1024 /1024 +"M"); } catch (filenotfoundException e) {e.printStackTrace (); } catch (ioexception e) {e.printStackTrace (); }}}.doc arquivo
Aqui usamos o WordExtractor para ler documentos do Word. WordExtractor vem do projeto da biblioteca POI da Apache. O endereço oficial de download é: https://poi.apache.org/download.html
importar java.io.fileInputStream; importar org.textMining.text.extraction.wordExtractor; public class WordTest {public static void main (string args []) lança exceção {new wordTest (). readbyother (); } public void readByText () lança exceção {FILEInputStream in = new FileInputStream ("c: //test.doc"); WordExtractor Extrator = new WordExtractor (); String str = extrator.extractText (in); System.out.println (str); }}