快速业务通道

Java版SLG游戏开发--数据的读取及保存 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-18
脚本省力。

核心代码如下:

package org.loon.simple.slg.utils; import java.io.IOException; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; /**   * Copyright 2008   *   * 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.   *   * @project loonframework   * @author chenpeng   * @email:ceponline@yahoo.com.cn   * @version 0.1   */ public class CSVConfigure {      /**       * 载入CSV数据后转化为指定类的Object[]       *       * @param fileName       * @param clazz       * @return       */      final static public Object[] loadPropertys(final String fileName,              final Class clazz) {          Object[] results = null;          try {              List properts = CSVConfigure.loadPropertys(fileName);              int size = properts.size();              results = (Object[]) Array.newInstance(clazz, size);              for (int i = 0; i < size; i++) {                  Map property = (Map) properts.get(i);                  Set set = property.entrySet();                  results[i] = clazz.newInstance();                  for (Iterator it = set.iterator(); it.hasNext();) {                      Entry entry = (Entry) it.next();                      ClassUtils.beanRegister(results[i],                              (String) entry.getKey(), (String) entry.getValue());                  }              }          } catch (Exception ex) {              throw new RuntimeException(ex+" "+fileName);          }          return results;      }      /**       * 载入CSV数据到List       *       * @param fileName       * @return       */      final static public List loadPropertys(final String fileName) {          List result = new ArrayList();          try {              CSVReader csv = new CSVReader(fileName);              List names = csv.readLineAsList();              int length = names.size();              for (; csv.ready();) {

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号