簡単な例。規則性は、余分なスペースまたはタブキーをキャンセルすることです
パッケージテスト4; java.io.bufferedreader; Import java.io.filereader; import java.io.ioexception; public class ExplacesQl {public static void main(string [] args){string filepath = explacesql.class.getResource( "")。getPath()+"aaa.txt"; //ファイルパスread(filepath);}/*** read content*/public static string read(string filepath){bufferedreader br = null; string line = null; // stringbuffer buffer(); try {//ファイルパスに従ってバッファー入力ストリームを作成します。 string str = ""; //ファイルの各行の読み取り、変更する必要がある行を変更し、バッファオブジェクトに配置します。 string [] dictionary = str.split( "// s {2、} |/t"); for(int i = 0; i <dictionary.length; i ++){str = "tablename値に挿入("+dictionary [0]+"、 '"+dictionary [1]+"'、"+dictionary [2]+"')"; } system.out.println(str); }} catch(Exception e){e.printstacktrace();}最後に{if(br!= null){// close stream try {br.close(); } catch(ioException e){br = null; }}} null;}}}}を返しますJavaは、TXTファイルをラインごとに読み取り、書き込みます
パッケージヘルプ; java.io.bufferedreader; Import java.io.bufferedwriter; Import java.io.file; Import java.io.fileinputStream; Import java.io.fileoutputStream; Import java.io.inputStreamReader; Import Java.io.OutputStreamwriter; Import Java.util.util.util.utl.hasmap;パブリッククラスtxtparseutils {private static final integer one = 1; public static void main(string [] args){map <string、integer> map = new hashmap <string、integer>(); /*データの読み取り*/try {bufferedreader br = new BufferedReader(new inputStreamReader(new FileInputStream(new File( "d:/reimbursement.txt"))、 "utf-8"));文字列linetxt = null; while((linetxt = br.readline())!= null){string [] names = linetxt.split( "、"); for(string name:name){if(map.keyset()。contains(name)){map.put(name、(map.get(name) + one)); } else {map.put(name、one); }}} br.close(); } catch(Exception e){System.err.println( "read errors:" + e); }/*出力データ*/try {bufferedwriter bw = new BufferedWriter(new outputStreamWriter(new FileOutputStream(new File( "d:/result.txt"))、 "utf-8")); for(string name:map.keyset()){bw.write(name + "" + map.get(name)); bw.newline(); } bw.close(); } catch(Exception e){System.err.println( "write errors:" + e); }}}TXTファイルの読み取りとスペースを使用して各行のデータを取得する上記のJava実装は、私があなたと共有するすべてのコンテンツです。私はそれがあなたに参照を与えることができることを願っています、そしてあなたがwulin.comをもっとサポートできることを願っています。