光与影的1/2
千里代码有问题了.您给我的这个方法可以按要求分开一部分,
但不知道为什么,同样的格式的字符串,同样的分割要求,有的用这个方法就不能按要求分好~
读这个文件:
public class Test8
{
public static void main(String[] args)
{
FileInput in = new FileInput("d:\\a.txt","d:\\cc.txt");
in.read();
}
}
class FileInput
{
private BufferedReader br;
private BufferedWriter bw;
public FileInput(String fileName,String outFileName)
{
try
{
br = new BufferedReader(new FileReader(fileName));
bw = new BufferedWriter(new FileWriter(outFileName));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void read() //读文件
{
String strIn;
try
{
while((strIn = br.readLine())!=null)
{
Matcher m = Pattern.compile("\\d\\s+").matcher(strIn);
if(m.find())
{
String out = m.group();
strIn = strIn.replaceAll(out,out.trim()+",");
System.out.println(strIn);
// toFormatIp(strIn);
write(strIn);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void write(String str) //写入文件
{
try
{
bw.write(str);
bw.newLine();
bw.flush();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}