微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

读写文件操作xml

需求:

就我给你截的那一段撒,左边为顶面深读,右边底面深度,在这之间他的岩性赋值为6.但这个太细了,我想要直接显示1823.625-1824.625为6.把中间的合并了


代码

package com.dhgate.spumanage.web.action;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test {
	public static void main(String[] args) {
		//读文件
        BufferedReader br = null;
        String sCurrentLine;
        int sameTime = 0;
        String lastNum = "";
		CSV csv = new CSV();
		CSV c2 = new CSV();
        try {
			br = new BufferedReader(new FileReader("D:\\Book1.csv"));
			while((sCurrentLine = br.readLine()) != null){
	            System.out.println(sCurrentLine);
	            String[] split = sCurrentLine.split(",");

	            System.out.println();
	            
	            if(split.length>=3){
	            	

	            	
	            	if(lastNum.equals(split[2])){
	            		sameTime++;
	            		csv.second = split[1];
	            		
	            	}else{
	            		sameTime = 0;
	            	}
	            	
	            	if(sameTime==0){
	            		csv.first=split[0];
	            		csv.second = split[1];
	            		csv.third = split[2];
	            	}
	            	
	            	lastNum = split[2];
	            	
	            	
	            	//写数据
	            	
	                FileWriter fw = new FileWriter("D:\\result.csv",true);//append true -->>new FileWrite(file,true);
	                BufferedWriter bw = new BufferedWriter(fw);
	                
	                if(!csv.third.equals(c2.third)){
	                	bw.write(c2.first+","+c2.second+","+c2.third+"\n");
	                }
	                
	                
	                bw.flush();
	                bw.close();
	            	
	                c2.first = csv.first;
	                c2.second = csv.second;
	                c2.third = csv.third;
	            }
	            
	        }
		} catch (FileNotFoundException e) {
			// Todo Auto-generated catch block
			e.printstacktrace();
		} catch (IOException e) {
			// Todo Auto-generated catch block
			e.printstacktrace();
		}
        
        
		//操作字符串
		
		//写文件
	}
}

class CSV {
	String first;
	String second;
	String third;
	public String getFirst() {
		return first;
	}
	public String getSecond() {
		return second;
	}
	public String getThird() {
		return third;
	}
	public void setFirst(String first) {
		this.first = first;
	}
	public void setSecond(String second) {
		this.second = second;
	}
	public void setThird(String third) {
		this.third = third;
	}
	
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。