Here you can find the source of splitStringFixedLen(String data, int interval)
public static String[] splitStringFixedLen(String data, int interval)
//package com.java2s; /**// w w w . ja va 2s .c o m * This file is part of Aion X Emu <aionxemu.com> * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with this software. If not, see <http://www.gnu.org/licenses/>. */ import java.util.List; import java.util.ArrayList; public class Main { public static String[] splitStringFixedLen(String data, int interval) { List<String> dataPiece = new ArrayList<String>(); int addedOffset; for (int offset = 0; offset < data.length(); offset += addedOffset) { String subData = data.substring(offset, Math.min(data.length(), (offset + interval))); addedOffset = subData.lastIndexOf('\n'); if (addedOffset >= 0) { subData = subData.substring(0, addedOffset); ++addedOffset; } else { addedOffset = interval; } dataPiece.add(subData); } String[] result = new String[dataPiece.size()]; dataPiece.toArray(result); return result; } }