今天,我的代碼可以工作,但它將2行分成2行,但這不是目標。 我想改變分割,我要劃分50線50線,而不是由2 2 如果我離開這樣的,我有2行 三個文件,如果我有135行,我想:更改分割數
- 拳文件:50線(我的文件的行1-50)和文件名是801
- 第二個文件:50線(我的文件的行51-100)和文件名是802
- 第三個文件:35行(我的文件的101-135行)和文件名是803.
在這裏,這是我的代碼:
private void MyCode(ProducerTemplate producerTemplate, InputStream content, String endpoint, String fileName, HashMap<String, Object> headers){
ArrayList<String> list = new ArrayList<String>();
String line;
long numSplits = 50; //Number of lines per split
int sourcesize=0; //Number of lines
int number = 800; //my filename
BufferedReader br = new BufferedReader(new InputStreamReader(content));
try{
while((line = br.readLine()) != null){
sourcesize++;
list.add(line); //add the lines in the arraylist
}
System.out.println("Lines in the file: " + sourcesize);
for(int i = 0 ; i <= list.size() ; i+=numSplits) {
String Filename = ""+ number;
System.out.println(Filename);
StringBuilder builder = new StringBuilder();
builder.append(list.get(i)).append(System.lineSeparator()).append(list.get(i+1));
producerTemplate.sendBodyAndHeader(endpoint, builder.toString(), "CamelFileName",Filename); //Used to forward lines and the file name
}
} catch (IOException e) {
e.printStackTrace();
}
}
我想:
for (int k=0;k<numSplits;k++) {
builder.append(list.get(i));
builder.append(System.lineSeparator());
}
如何改變分割? 如何削減我的arraylist
全部50個事件?
請解釋一下你的問題,「2行2行分割」並沒有給我們太多的提示。 –
對不起@Jaroslaw Pawlak,但我想調整我的代碼。 我不想分割我的文件全部2行,但每隔50行。 – Krokodeeal
我仍然不知道你的問題是什麼,你想做什麼。 –