Regular Expression Regular Expression - 2 (Java)

xiaoxiao2021-03-06  67

One is achieved in Java, found that Java's regular expression is slightly different, and it also feels that Java's read and write files are not very elegant.

/ * * Created on 2004-10-1 * / import java.util.regex. *; Import java.io. *; / ** * @Author dancefire * / public class datafilter {public static void main (String [] args ) {If (args.length <2) {system.err.println ("please enter 2 filenames (eg in.txt out.txt)); return;} string strin = null, strout = null; // Get string From a file strin = readfile (args [0]); // process strout = filter (STRIN); // Store Result Into a file writefile (args [1], strout);} private static void writefile (String FileName, String Data) {bufferedWriter WR = null; try {wr = new bufferedWriter (new filewriter); wr.write (data);} catch (exception e) {E.PrintStackTrace ();} finally {try {if (WR ! = null) Wr.close ();} catch (Exception e) {e.printStackTrace ();}} return;} private static String readFile (String filename) {String strRet = null; BufferedReader rd = null; try {rd = new BufferedReader (new FileReader (filename)); String line = NULL; STRINGBUFFER SB = New StringBuffer (); while ((line = rd.readline ())! = null) {sb.append (line);} strret = sb.toString ();} catch (exception e) {e .printstacktrace (); finally {try {if (rd! =

转载请注明原文地址:https://www.9cbs.com/read-110543.html

New Post(0)