package
extractors;
import
java.io.ByteArrayOutputStream;
import
java.io.File;
import
java.io.FileInputStream;
public
classExtractorTXT {
public ExtractorTXT() {
}
public String toString(File f) {
String result =
" ";
try {
FileInputStream in =
new FileInputStream(f);
byte[] b = null;
ByteArrayOutputStream out =
new ByteArrayOutputStream();
while (in.available() != 0) {
out.write(in.read());
}
b = out.toByteArray();
if (b != null) {
result =
new String(b);
}
in.close();
out.close();
}
catch (Exception ex) {
System.
out.println("Read fail! ");
}
return result;
}
public void fromatFile(String[] list) {
try {
for (int i = 0; i < list.length; i++) {
String one = (String) list[i];
String[] contents = one.split(
",");
System.
out.println("Employee->" + (i + 1));
System.
out.println("Employee Name:" + contents[0]);
System.
out.println("Employee ID:" + contents[1]);
System.
out.println("Employee Department:" + contents[2]);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String args[]) {
File file =
new File("D:\\TxtExtractor.txt ");
ExtractorTXT t =
new ExtractorTXT();
String str = t.toString(file);
String[] s = str.split(
"\\.");
System.
out.println(s.length);
System.
out.println(str);
t.fromatFile(s);
}
}