Home > Back-end > Learn Java read TXT file data, converted to an int array, a lot more at the back of the original dat
Learn Java read TXT file data, converted to an int array, a lot more at the back of the original dat
Time:09-27
Package QuickSort;
import java.io.BufferedReader; import java.io.File; Import the Java. IO. FileReader;
Public class getTxt {
Public static void main (String [] args) { //TODO Auto - generated method stub
The File File=new File (" F:/1. TXT "); GetTxt gt=new getTxt (); Int [b]=gt. Txt (file); for(int i=0; iSystem. The out. Print (b [I] + ""); }
}
Public static int [] Txt File (filePath) { Try { BufferedReader br=new BufferedReader (new FileReader filePath ()); String message=""; The String line=null; While ((line=br. ReadLine ())!=null) { Message=message + "" + line; } Message=message. The trim ();//remove end blank String s=[] message. The split (" ");//data separated by a space between Int a []=new int [message length ()]; for(int i=0; iA [I]=Integer. The valueOf (s [I]); } br.close(); return a; }
The catch (Exception e) { //TODO: handle the exception e.printStackTrace(); return null; } } }