General text files
we take the log file. log file as an example:
Import Java.io.BufferedReader;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import java.io.IOException;
public class File_test {
/**
* @param args
*
/public static void main (string[] args) {
file File = New File ("D:\\logserrormsg.log");
if (file.exists ()) {
System.out.println ("This file exists");
} else {
System.out.println ("This file does not exist");
}
try {
FileReader fr = new FileReader (file);
BufferedReader br = new BufferedReader (FR);
String s;
while ((S=br.readline ())!=null) {
System.out.println (s);
}
SYSTEM.OUT.PRINTLN ("File size is (MB):" +new fileinputstream (Files). Available ()/1024/1024 + "M");
} catch (FileNotFoundException e) {
e.printstacktrace ();
} catch (IOException e) {
e.printstacktrace (); c30/>}}}
. doc files
Here we use Wordextractor to read Word documents, wordextractor from Apache POI Class Library project, official download address: https://poi.apache.org/download.html
Import Java.io.FileInputStream;
Import Org.textmining.text.extraction.WordExtractor;
public class Wordtest {public
static void Main (String args[]) throws Exception {
new Wordtest (). Readbyother ();
} public
void Readbytext () throws Exception {
FileInputStream in = new FileInputStream ("C://test.doc");
Wordextractor extractor = new Wordextractor ();
String str = Extractor.extracttext (in);
System.out.println (str);
}