|
@@ -0,0 +1,66 @@
|
|
|
|
|
+package com.uas.search.console.data;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
|
+import java.io.FileReader;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
+
|
|
|
|
|
+public class PropertyValueSplit {
|
|
|
|
|
+
|
|
|
|
|
+ // 单个文件存储的最大数据数目
|
|
|
|
|
+ public static final int SINGLE_FILE_MAX_SIZE = 1000000;
|
|
|
|
|
+
|
|
|
|
|
+ // 器件和属性值两个文本文件的路径
|
|
|
|
|
+ private static final String DATA_DIR = "C:\\Users\\sunyj-pc\\Desktop\\temp\\data\\test";
|
|
|
|
|
+
|
|
|
|
|
+ // public static void main(String[] args) {
|
|
|
|
|
+ // copy();
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ public static void copy() {
|
|
|
|
|
+ BufferedReader bufferedReader = null;
|
|
|
|
|
+ PrintWriter printWriter = null;
|
|
|
|
|
+ // 分成多个文件存储
|
|
|
|
|
+ int fileIndex = 1;
|
|
|
|
|
+ try {
|
|
|
|
|
+ File file = new File(DATA_DIR + "\\copy");
|
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
|
+ file.mkdirs();
|
|
|
|
|
+ }
|
|
|
|
|
+ bufferedReader = new BufferedReader(new FileReader(DATA_DIR + "\\PropertyValue.txt"));
|
|
|
|
|
+ printWriter = new PrintWriter(DATA_DIR + "\\copy\\pv_copy" + fileIndex + ".txt");
|
|
|
|
|
+ String propertyValueLine = null;
|
|
|
|
|
+ int dataCount = 0;
|
|
|
|
|
+ while (!StringUtils.isEmpty(propertyValueLine = bufferedReader.readLine())) {
|
|
|
|
|
+ dataCount++;
|
|
|
|
|
+ // 一个文件存放SINGLE_FILE_MAX_SIZE条数据,一旦超过,写入新的文件
|
|
|
|
|
+ if (dataCount > SINGLE_FILE_MAX_SIZE) {
|
|
|
|
|
+ System.out.println("--------------------------------new file" + fileIndex);
|
|
|
|
|
+ dataCount = 1;
|
|
|
|
|
+ printWriter.flush();
|
|
|
|
|
+ printWriter.close();
|
|
|
|
|
+ fileIndex++;
|
|
|
|
|
+ printWriter = new PrintWriter(DATA_DIR + "\\copy\\pv_copy" + fileIndex + ".txt");
|
|
|
|
|
+ }
|
|
|
|
|
+ printWriter.write(propertyValueLine + "\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ printWriter.flush();
|
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ try {
|
|
|
|
|
+ bufferedReader.close();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ printWriter.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|