サブページ リスト |
私が作成しているSnippetというかサンプルコードを掲載しておきます。
誰でも思いつくコードなのでオリジナリティーは主張しません。ですがライセンスは無いと困る場合もありますので、すべてApache 2.0 ライセンスとします。
Apache 2.0 ライセンス
/*
*
* Copyright 2010 akjava.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*
*/
CSVをパース
複雑のはOpenCSVなどCSVParser APIをお使いください
改行コード固定ですが、普通にテキスト全体をArrayに変換します。
public static String[][] csvToArray(String line,char separator){
line=ValueUtils.toNLineSeparator(line);
String[] lines=line.split("\n");
String ret[][]=new String[lines.length][0];
for (int i = 0; i < lines.length; i++) {
String csv[]=lines[i].split(""+separator);
ret[i]=new String[csv.length];
for (int j = 0; j < csv.length; j++) {
ret[i][j]=csv[j];
}
}
return ret;
}