Option是什么??
是那个包的?你的文件内容是
new Option("北京-民熙号","2932"),
new Option("北京-麒麟号","2933"),
new Option("北京-定远号","2934"),
new Option("上海-昭君号","2935"),
new Option("上海-蓬景号","2936"),
new Option("上海-海玄号","2937"),
new Option("上海-曙光号","2938"),
new Option("上海-凯旋号","2939"),
.
.
.
.
.
疑惑了?
是那个包的?你的文件内容是
new Option("北京-民熙号","2932"),
new Option("北京-麒麟号","2933"),
new Option("北京-定远号","2934"),
new Option("上海-昭君号","2935"),
new Option("上海-蓬景号","2936"),
new Option("上海-海玄号","2937"),
new Option("上海-曙光号","2938"),
new Option("上海-凯旋号","2939"),
.
.
.
.
.
疑惑了?
解决方案 »
- awt下对于图片加载的一些困惑希望各位解答!
- java 实现http post object功能
- 在使用Swing中的JTree的时候由于数据量过大,应该如何优化来减少加载时间?
- ZipInputStream的问题 散200分~~~~
- 有关comparable,谢谢!!!!
- 关于字符串
- static 方法和普通的方法有什么优点缺点呢?
- ******* 100分 提供一个jbuilder for umix(red hat linux or solaris )的下载地址
- 如何让HashMap的先进先出?
- 请问JAVA如何编写多线程共享一个变量?注意是不同的构造函数做出的线程。
- 关于向JTable里面加入JCheckBox的问题!
- 求教:如何在JWindow上显示滚动字幕
import java.util.regex.*;public class TestFile
{
public static void main(String[] args)
{
try
{
String inFile = args[0];
String outFile = args[1]; String line;
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream(inFile), "GB2312")); BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(outFile),"GB2312")); Pattern p = Pattern.compile("(\"[^\"]*?\")([^\"]*?)(\"[^\"]*?\")");
String aLine = null;
while((aLine = in.readLine()) != null) { Matcher m = p.matcher(aLine);
out.write(m.replaceAll("$1$2$1"));
out.newLine();
}
in.close();
out.close();
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
} }
}
BufferedReader bReader = new BufferedReader(reader);
FileWriter writer = new FileWriter(new File("d:/b.txt"));
BufferedWriter bWriter = new BufferedWriter(writer);
String str = "";
String temp;
while(true) {
str = bReader.readLine();
if (str != null) {
temp = str.substring(str.indexOf("\""), str.indexOf("\"") + 8);
str = str.substring(0, str.indexOf(",") + 1) + temp + "),";
bWriter.write(str);
bWriter.newLine();
} else {
break;
}
}
reader.close();
bReader.close();
bWriter.close();
writer.close();
{
try
{
File file = new File("Y:/src.txt");
File destfile = new File("Y:/dest.txt");
FileInputStream in = new FileInputStream(file);
FileOutputStream out = new FileOutputStream(destfile);
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "GBK"));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "GBK"));
String str = "";
String ori = "";
String dest = "";
while ((str = reader.readLine()) != null)
{
ori = str.substring(str.indexOf("\"") + 1, str.indexOf(",") - 1);
System.out.println("ori=" + ori);
dest = str.substring(0, str.indexOf(",") + 2) + ori + "\")";
System.out.println("dest=" + dest);
writer.newLine();
writer.write(dest, 0, dest.length());
writer.flush();
}
}
catch (IOException io)
{
io.printStackTrace();
}
}src.txt内容是
new Option("北京-民熙号","2932"),
new Option("北京-麒麟号","2933"),
new Option("北京-定远号","2934"),
new Option("上海-昭君号","2935"),
new Option("上海-蓬景号","2936"),
new Option("上海-海玄号","2937"),
new Option("上海-曙光号","2938"),
new Option("上海-凯旋号","2939"),
* strReadFile:源文件路径(如:C:\test.txt)
* strWriteFile:存放替换后内容的文件路径(如:C:\test1.txt)
*/
public static void fileTransfer(String strReadFile,String strWriteFile)
{
try
{
File readFile = new File(strReadFile);
BufferedReader br = new BufferedReader(new FileReader(readFile));
File writeFile = new File(strWriteFile);
BufferedWriter bw = new BufferedWriter(new FileWriter(writeFile,true));
String strOneOpetion = new String();
while((strOneOpetion=br.readLine())!=null)
{
if(strOneOpetion.length()>0)
{
int iIndex1 = strOneOpetion.indexOf("(");
int iIndex2 = strOneOpetion.indexOf(")");
if(iIndex1!=-1 && iIndex2!=-1)
{
String strTemp = strOneOpetion.substring(iIndex1+1,iIndex2);
String[] arrPartValue = strTemp.split(",");
if(arrPartValue==null && arrPartValue.length<2) continue;
strOneOpetion = strOneOpetion.replaceAll(arrPartValue[1],arrPartValue[0]);
bw.write(strOneOpetion+"\n");
bw.flush();
}
}
}
br.close();
bw.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
BufferedReader br=new BufferedReader(fr);
FileWriter fw=new FileWriter("newfile");
BufferedWriter bw=new BufferedWriter(fw);
String s;
StringBuffer sb;
while ((s=br.readLine())!=null){
int start1,end1,start2,end2;
start1=s.indexOf('/"');
end1=s.indexOf('/"',start1);
s1=s.substring(start1+1,end1);
start2=s.indexOf('/"',end1);
end2=s.indexOf('/"',start2);
sb=new StringBuffer(s);
sb.replace(start2+1,end2,s1);
bw.write(sb.toString());
}
只是随便写写,没测试过,望有所帮助