日期:2014-05-20 浏览次数:20634 次
public static void main(String[] args) throws Exception{ FileOutputStream dstout = new FileOutputStream("d:/dst.txt"); InputStream in = new FileInputStream("d:/src.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = ""; while((line=br.readLine())!=null){ System.out.println(line); String lines[] = line.split("\\s",2); dstout.write(("FILE="+lines[0]).getBytes()); dstout.write("\r\n".getBytes()); dstout.write(("TITLE="+lines[1]).getBytes()); dstout.write("\r\n".getBytes()); } in.close(); br.close(); dstout.close(); }
------解决方案--------------------
public static void main(String[] args) { String str = "http://sy3.cietv.com:554/live.soooner.com/5 CCTV-1 综合频道"; String reg = "(^http://.*? )(.*)"; Pattern p = Pattern.compile(reg); Matcher match = p.matcher(str); StringBuffer result = new StringBuffer(); int fileIndex = 1; int titleIndex = 2; String fileUrl = null; while (match.find()) { fileUrl = match.group(fileIndex); fileUrl = fileUrl.substring(0, fileUrl.length() - 1); result.append("FILE=").append(fileUrl).append("\n"); result.append("TITLE=").append(match.group(titleIndex)) .append("\n"); } System.out.println(result.toString()); }