This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.OutputStreamWriter; | |
import java.util.HashMap; | |
import java.util.regex.Pattern; | |
public class Main { | |
HashMap<String, String> Template = new HashMap<String, String>(); | |
String[] Fields = { "datetime", "recordtype", "msisn", "imei", | |
"otherparty", "typenumber", "callduration", "cellid", }; | |
void initTemplate() { | |
for (String field : Fields) { | |
Template.put(field, ""); | |
} | |
} | |
public static String[] fastSplit(String str, String[] arr) { | |
int start = 0; | |
int len = arr.length; | |
int idx; | |
for (int i = 0; i < len; i++) { | |
idx = str.indexOf("\t", start); | |
if (idx <= 0) { | |
arr[i] = str.substring(start); | |
break; | |
} | |
arr[i] = str.substring(start, idx); | |
start = idx + 1; | |
} | |
return arr; | |
} | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
try { | |
// FileReader f = new FileReader("bit.t"); | |
String text; | |
FileInputStream fis = new FileInputStream( | |
"500m.txt"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader( | |
new BufferedInputStream(fis, 8 * 131072)), 131072); | |
FileOutputStream fos = new FileOutputStream( | |
"test10"); | |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( | |
new BufferedOutputStream(fos, 8 * 131072)), 131072); | |
StringBuilder result = new StringBuilder(256); | |
String[] column = new String[8]; | |
Pattern sep = Pattern.compile("\t"); | |
while ((text = reader.readLine()) != null) { | |
// column = sep.split(text); | |
column = fastSplit(text, column); | |
result.setLength(0); | |
for (String e : column) { | |
result.append(e); | |
result.append(";"); | |
} | |
writer.write(result.toString() + "\r\n"); | |
} | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment