import java.io.*;
public class TestFile3 {
static String beginNo; //起始的一段小票号
static String tempString = null;//整行内容
public static void main(String[] args) throws IOException{
int line = 1; //记录行号
File file = new File("C://myJava//eclipse//20070708.sql");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));//由于BufferedReader具有readLine()方法,可以一行行的读进记录
FileWriter fw = new FileWriter("C://myJava//eclipse//200707088.sql");
//一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null){
if (line==1)
{
fw.write(tempString,0,tempString.length());
beginNo="0001";//tempString.substring(515, 520);
fw.write("/r/n");//windows的回车换行符一定要这样写,顺序都不能错。
System.getProperty("line.separator");
line++;
}
else
{
if(tempString.charAt(530)=='1')
{
int n=Integer.parseInt(beginNo);
n=n+1;
//System.out.println(n);
beginNo=n+"";
switch(beginNo.length())
{
case 1:
beginNo="000"+beginNo;
break;
case 2:
beginNo="00"+beginNo;
break;
case 3:
beginNo="0"+beginNo;
break;
}
fw.write(tempString,0,515);
fw.write(beginNo);
fw.write(tempString,520,tempString.length()-520);
fw.write("/r/n");
System.getProperty("line.separator");
line++;
}
else
{
fw.write(tempString,0,515);
fw.write(beginNo);
fw.write(tempString,520,tempString.length()-520);
fw.write("/r/n");
System.getProperty("line.separator");
line++;
}
}
}
fw.flush();
fw.close();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (reader != null){
try {
reader.close();
}
catch (IOException e1) {
}
}
}
}
}
public class TestFile3 {
static String beginNo; //起始的一段小票号
static String tempString = null;//整行内容
public static void main(String[] args) throws IOException{
int line = 1; //记录行号
File file = new File("C://myJava//eclipse//20070708.sql");
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));//由于BufferedReader具有readLine()方法,可以一行行的读进记录
FileWriter fw = new FileWriter("C://myJava//eclipse//200707088.sql");
//一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null){
if (line==1)
{
fw.write(tempString,0,tempString.length());
beginNo="0001";//tempString.substring(515, 520);
fw.write("/r/n");//windows的回车换行符一定要这样写,顺序都不能错。
System.getProperty("line.separator");
line++;
}
else
{
if(tempString.charAt(530)=='1')
{
int n=Integer.parseInt(beginNo);
n=n+1;
//System.out.println(n);
beginNo=n+"";
switch(beginNo.length())
{
case 1:
beginNo="000"+beginNo;
break;
case 2:
beginNo="00"+beginNo;
break;
case 3:
beginNo="0"+beginNo;
break;
}
fw.write(tempString,0,515);
fw.write(beginNo);
fw.write(tempString,520,tempString.length()-520);
fw.write("/r/n");
System.getProperty("line.separator");
line++;
}
else
{
fw.write(tempString,0,515);
fw.write(beginNo);
fw.write(tempString,520,tempString.length()-520);
fw.write("/r/n");
System.getProperty("line.separator");
line++;
}
}
}
fw.flush();
fw.close();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (reader != null){
try {
reader.close();
}
catch (IOException e1) {
}
}
}
}
}