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);

}

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2022-01-05
  • 2021-08-02
猜你喜欢
  • 2022-02-11
  • 2022-12-23
  • 2021-11-30
  • 2022-02-09
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
相关资源
相似解决方案