⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readtxt.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
/*
 * 创建日期 2006-9-9
 * 作    者  朱 闰
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

package com.tongtu.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.tongtu.Dao.plan.PlanDAO;
import com.tongtu.Dao.plan.planDao.PlanDAOImpl;
import com.tongtu.Dao.role.RoleDAO;
import com.tongtu.Dao.role.roleDao.RoleDAOImpl;
import com.tongtu.comm.loadData.FileOperate;

public class ReadTxt {
	
	  public String[] readFile(String fileName) {
	    Vector ve = new Vector();
	    try {
	      BufferedReader in = new BufferedReader(new InputStreamReader(new
	          FileInputStream(fileName)));
	      String line = new String("");
	      String txtStr="";
	      int i = 0;
	      for (line = in.readLine(); line != null; line = in.readLine(), i++) {
	    	
	    	  txtStr=line.trim().replace("\"","");
	    	 // if (i==203)
	             // System.out.println("读取第"+ i + "行: " + txtStr);
	        ve.add(txtStr);
	      }
	    }
	    catch (Exception ex) {
	      System.out.print(ex);
	    }
	    String[] temp = new String[ve.size()];
	    for (int i = 0; i < ve.size(); i++) {
	      temp[i] = ve.elementAt(i) + "";
	    }
	    return temp;
	  }
	  
	  public void loadData(String [] txt,String code){
		  
		  String  rowStr = "";
			PlanDAO planDao = new PlanDAOImpl();
			RoleDAO roleDao  = new RoleDAOImpl();
			double lc = 0.0;
			double xzljkd = 0.0;
			double xzlmkd = 0.0;
			double jhlc = 0.0;
			double jhljkd = 0.0;
			double jhlmkd = 0.0;
			double jhje = 0.00;
			double jhsb = 0.00;
			int renkou = 0;
			int shouru = 0;
			String townCode = "";
			String villageCode = "";
			String townName = "";
			for (int i = 1; i < txt.length ;i++){
				rowStr = txt[i];
				if (rowStr.length() == 0){
					System.out.println("错误行:" + rowStr);
					continue;
				}
				String[] values = rowStr.split("\t");
				if (values == null) continue;
				PlanDetail pd = new PlanDetail();
				pd.setPlanType(2);
			    pd.setRoadName(values[0].trim());
			//	townCode = roleDao.getTownCode(values[1].trim(),code);
				
					pd.setTownName(values[1].trim());
					pd.setTownsId(code);
					pd.setVillagesId(code);
			
			
				pd.setVillageName(values[3].trim());
			
				pd.setVillageType("0;0;0;");
			    pd.setQdmc(values[4]);
			    pd.setQdloc(values[5]);
			    pd.setZjd1mc(values[6]);
			    pd.setZjd1loc(values[7].trim());
			    pd.setZjd2mc(values[8].trim());
			    pd.setZjd2loc(values[9].trim());
			    pd.setZjd3mc(values[10].trim());
			    pd.setZjd3loc(values[11].trim());
			    pd.setZdmc(values[12].trim());
			    pd.setZdloc(values[13].trim());
			    if (values[14].trim().length() != 0)
			    	{
			    	
			    	try
			        {
			    		lc = Double.parseDouble(values[14].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	lc = 0.0;
			        }
			    	}
			    pd.setLc_xz(lc);
			    if (values[15].trim().length() != 0)
                   {
			    	
			    	try
			        {
			    		xzljkd = Double.parseDouble(values[15].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	xzljkd = 0.0;
			        }
			    	}
			    
			    pd.setLjkd_xz(xzljkd);
			    if (values[16].trim().length() != 0)
                    {
			    	
			    	try
			        {
			    		xzlmkd = Double.parseDouble(values[16].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	xzlmkd = 0.0;
			        }
			    	}
			    	
			    pd.setLmkd_xz(xzlmkd);
			    pd.setLmlx_xz(values[17].trim());
			    
			    
			    if (values[18].trim().length() != 0)
                     {
			    	
			    	try
			        {
			    		jhlc = Double.parseDouble(values[18].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	jhlc = 0.0;
			        }
			    	}
			    
			    pd.setMilemeter(jhlc);
			    if (values[19].trim().length() != 0)
                     {
			    	
			    	try
			        {
			    		jhljkd = Double.parseDouble(values[19].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	jhljkd = 0.0;
			        }
			    	}
			    
			    pd.setRoadbedWidth(jhljkd);
			    
			    if (values[20].trim().length() != 0)
                  {
			    	
			    	try
			        {
			    		jhlmkd = Double.parseDouble(values[20].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	jhlmkd = 0.0;
			        }
			    	}
			    
			    
			    pd.setRoadSurfaceWidth(jhlmkd);
			    pd.setRoadSurfaceType(0);
			    
			    if (values[22].trim().length() != 0)
                   {
			    	
			    	try
			        {
			    		jhje = Double.parseDouble(values[22].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	jhje = 0.0;
			        }
			    	}
			    	
			    
				pd.setInvest(jhje);
				
				  if (values[23].trim().length() != 0)
				  {
				    	
				    	try
				        {
				    		  jhsb = Double.parseDouble(values[23].trim());
				        }catch (NumberFormatException e ){
				        	e.printStackTrace();
				        	jhsb = 0.0;
				        }
				    	}
					
				pd.setProvinceSubsidy(jhsb);
				String start = "null";
				String end = "null";
				  if (values[24].trim().length() != 0)
					  start  = values[24].trim();
				pd.setStartTime(start);
				  if (values[25].trim().length() != 0)
					  end  = values[25].trim();
				pd.setEndTime(end);
				
				  if (values[26].trim().length() != 0)
				  {	try
				        {
				    		renkou = Integer.parseInt(values[26].trim());
				        }catch (NumberFormatException e ){
				        	e.printStackTrace();
				        	renkou = 0;
				        }
				  }
				pd.setRk(renkou);
				
				  if (values[27].trim().length() != 0)
				  {   	
				  try
			        {
					  shouru = Integer.parseInt(values[27].trim());
			        }catch (NumberFormatException e ){
			        	e.printStackTrace();
			        	shouru = 0;
			        }
				  }
				pd.setSr(shouru);
				
				pd.setJjzw(values[28].trim());
				pd.setGraphicFile(values[30].trim());
				//System.out.println("arraySize===" + values.length);
				if (values.length == 32)
				  pd.setAttachFile(values[29].trim() + "  航迹: " + values[31].trim());
				else 
				  pd.setAttachFile(values[29].trim() + "  航迹: ");
				
				planDao.addPlanInfo(pd);//
				
			}
		  
	  }

	  public void copyFile(File[] files){
		  RoleDAO roleDao  = new RoleDAOImpl();
		  FileOperate fo = new FileOperate();
		  for (int i = 0; i < files.length;i++){
			  File f = files[i];
			  String filePath = f.getAbsolutePath() ;
				String temp = filePath.replace("\\", ";");
				String[] filestr = temp.split(";");
				String xianName =  filestr[filestr.length-1];
				String cityName = filestr[filestr.length-2];
				String xianCode = roleDao.getCountyCode(xianName);
				String cityCode = City.getCityCode(cityName);
				if (xianCode.length() == 0 && xianName.indexOf("市区")!= -1){
					xianCode = roleDao.getCountyCode2("", cityCode.substring(0,4));
					System.out.println("===============" + xianCode);
				}
			  File jpgFile = new File(filePath);
			  File[] jpgFiles = jpgFile.listFiles();
			  for (int j = 0; j < jpgFiles.length;j++){
				  File oldFile = jpgFiles[j];
				  String fileName = oldFile.getName();
				  String oldFilePath = oldFile.getAbsolutePath();
				  fo.newFolder("d:\\allpic\\" + xianCode);
				  fo.copyFile(oldFile.getAbsolutePath(), "d:\\allpic\\" + xianCode + "\\" + fileName);
				  System.out.println("files:" + oldFilePath);
			  }
		  }
		  
	  }
	  
	  public void test(){
		  PlanDAO planDao = new PlanDAOImpl();
		  List planList = planDao.getPlanList();
		  for (int i = 0; i < planList.size();i++){
			 PlanDetail pd = (PlanDetail)planList.get(i);
			  int planId = pd.getPlanId();
			  String townName = pd.getTownName();
			  System.out.println("PlanId===" + planId + "      === townName==" + townName);
			  planDao.updatePlan(townName, planId);
		  }
	  }
	public static void  main(String[] args){
		RoleDAO roleDao  = new RoleDAOImpl();
		ReadTxt rt = new ReadTxt();
		String path = "D:\\非沟通TXT";
		//String path = "D:\\AllJPG\\宣城市";
		String xianName = "";
		String pathStr = "";
		String code = "";
		String cityName = "";
		String cityCode = "";
		File file = new File(path);
		File [] f = file.listFiles();
		for (int j = 0; j< f.length;j++){
			String cityPath = f[j].getAbsolutePath();
			File shiFile = new File(cityPath);
			File [] xianFile = shiFile.listFiles();
   		    pathStr = f[j].getAbsolutePath();
			String temp = pathStr.replace("\\", ";");
			String[] filestr = temp.split(";");
			
			cityName = filestr[filestr.length-1];
			System.out.println("======city===" + cityName);
	
			for (int i = 0; xianFile!=null && i <xianFile.length;i++){
				pathStr = xianFile[i].getAbsolutePath();
				String temp1 = pathStr.replace("\\", ";");
				String[] filestr1 = temp1.split(";");
				xianName = filestr1[filestr1.length-1];
				System.out.println("正在导入" + xianName + "数据...");
				cityCode = City.getCityCode(cityName);
				code = roleDao.getCountyCode(xianName);
			   //System.out.println(xianFile[i].getAbsolutePath());
				System.out.println("========Code==========" + code);
				if (code.length() == 0 && xianName.indexOf("市区")!= -1){
					code = roleDao.getCountyCode2("", cityCode.substring(0,4));
					
				}
				String []txt = rt.readFile(xianFile[i].getAbsolutePath()+ "\\乡村道非沟通行政村.txt");
				rt.loadData(txt,code);      
			
			}
		}

		
		
		
//		FileOperate fo = new FileOperate();
//		 List countyList = roleDao.getAllCountyList();
//		 for (int i = 0; i < countyList.size();i++){
//			 County county = (County)countyList.get(i);
//			 code = county.getCountyCode();
//			 System.out.println("path===d:\\allpic\\" +code );
//			 fo.newFolder("d:\\allpic\\"+code);
//		 }

		// rt.copyFile(f);
	//	rt.test();
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -