Bukkit插件编程中.yml配置文件的创建和读取
package com.sklm.config; import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map; public class PluginConfig { public static HashMap<String, Object> configMap = new HashMap<String,Object>();
public static String configPath = null;
public PluginConfig() {
try {
this.configPath = this.createFile();
this.readConfig();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 创建配置文件
* @return 返回创建文件的标准路径
* @throws IOException
*/
public String createFile() throws IOException {
boolean hasFile = true;
File plugins = null;
File messageConfig = null;
File messageBoard = null;
plugins = new File("./plugins");
if(!plugins.exists()) {
plugins.mkdirs();
}else {
messageBoard = new File(plugins.getCanonicalPath(),"messageBoard");
if(!messageBoard.exists()) {
messageBoard.mkdirs();
}else {
messageConfig = new File(messageBoard.getCanonicalPath(),"messageBoardConfig.yml");
if(!(hasFile=messageConfig.exists())) {
messageConfig.createNewFile();
}
}
}
if(!hasFile) {
//Bukkit.getLogger().info("BufferedOutputStream"+messageConfig.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(messageConfig.getCanonicalPath().toString()); //
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(new String(" timerOut=10").getBytes());
if(bos != null) {
bos.close();
}
}
return messageConfig.getCanonicalPath().toString();
}
/**
* 读取配置文件中的信息
* @author SK_03
*
*/
public void readConfig() {
String path;
try {
int len = 0;
path = this.createFile();
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
while((len=br.read()) != -1) {
String configInfo = br.readLine();
if(configInfo != null && !(configInfo.contains("##"))) { //如果读取的内容不为空或者不是注释,则执行下面语句
//System.out.println(configInfo);
String[] configArray = configInfo.split("=");
//System.out.println(configArray[0]+configArray[1]);
configMap.put(configArray[0], configArray[1]);
//System.out.println(configArray[0].toString()+"="+configArray[1]);
}
}
if(br != null) {
br.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
Bukkit插件编程中.yml配置文件的创建和读取的更多相关文章
- SpringBoot中yml配置文件
1.yml配置文件书写格式 格式是在普通配置文件中以“.”分割的属性名称,该为“: ”和换行. 例子: //普通格式 spring.datasource.driver-class-name=com.m ...
- Spring Boot中yml配置文件Map集合注入及使用方式
yml配置文件 maps: "{key1: 'value1', key2: 'value2'}" java中 @Value("#{${maps}}") priv ...
- Spring Boot 中yml配置文件
步骤一:yml格式 现在大家发现,在springboot里还是要用到配置文件的. 除了使用.properties外,springboot还支持 yml格式. 个人觉得yml格式的可读性和..prope ...
- Bukkit插件编程之检测玩家受到的伤害是来自投射类武器还是近身武器
package com.sklm.lhb.listener; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; impo ...
- 《python核心编程》笔记——文件的创建、读取和显示
创建文件(makeTextFile.py)脚本提醒用户输入一个尚不存在的文件名,然后由用户输入文件每一行,最后将所有文本写入文本文件 #!/usr/bin/env python 'makeTextFi ...
- jsp中excel文件的创建与读取
1.创建excel文件//这里的jxl不是java的标准jar包,需要在项目中另外加载 import jxl.Workbook; import jxl.write.Label; import jxl. ...
- (蓝牙)网络编程中,使用InputStream read方法读取数据阻塞的解决方法
问题如题,这个问题困扰了我好几天,今天终于解决了,感谢[1]. 首先,我要做的是android手机和电脑进行蓝牙通信,android发一句话,电脑端程序至少就要做到接受到那句话.android端发送信 ...
- Qt多线程编程中的对象线程与函数执行线程
近来用Qt编写一段多线程的TcpSocket通信程序,被其中Qt中报的几个warning搞晕了,一会儿是说“Cannot create children for a parent that is in ...
- 初探Delphi中的插件编程
前言 我写Delphi程序是从MIS系统入门的,开始尝试子系统划分的时候采用的是MDI窗体的结构.随着系统功能的扩充,不断有新的子系统加入系统中,单个工程会变得非常大,每次做一点修改都要重新编译,单个 ...
随机推荐
- listview控件专题
listview控件加CheckBox 窗口load: listViewLayersName.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderS ...
- typedef define typedef可以使程序参数化,提高程序的可移植性。
小结: 1. typedef并没有创建一个新类型,它只是为某个已存在的类型增加了一个新的名称而已: 2. typedef声明也没有证据新的语义:通过这种方式声明的变量与通过普通方式声明的变量具有完全相 ...
- [dpdk] dpdk多线程任务调度
DPDK下的线程,叫做EAL线程. EAL线程默认是与CPU core一对一绑定的,这样的话,有一些实时性,计算量不高的任务独占CORE是一种浪费,大概找了如下几种解决方案. 1. dpdk seri ...
- [administrative][archlinux][netctl][wpa_supplicant] 查看WIFI链接信息
当使用 netctl + wpa_supplicant的时候,环境里同时存在好多个WIFI,而我同时有配置了他们的密钥信息在配置文件中. 那么我该如何查看,我当前链接到了哪个WIFI上? /home/ ...
- 图->存储结构->邻接多重表
文字描述 邻接多重表是无向图的另一种链式存储结构. 虽然邻接表是无向图的一种很有效的存储结构,在邻接表中容易求得顶点和边的各种信息. 但是,在邻接表中每一条边(vi,vj)有两个结点,分别在第i个和第 ...
- webpack打包配置模板
/** * Created by zzq on 2017/3/26. *///__dirname是node.js中的一个全局变量,它指向当前执行脚本所在的目录module.exports = {//注 ...
- Python摸爬滚打之day04----基本数据类型(列表,元组)
1.列表 列表是可变的, 有序的数据类型,列表是按照添加顺序来保存的,可以存放各种数据类型. 1.1 列表的切片(同字符串) 1.2 列表的增删改查 注意: 列表是可以直接在列表上面进行操 ...
- 【Python爬虫】Requests库的基本使用
Requests库的基本使用 阅读目录 基本的GET请求 带参数的GET请求 解析Json 获取二进制数据 添加headers 基本的POST请求 response属性 文件上传 获取cookie 会 ...
- caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: 'to_string' is not a member of 'std'解决方法
https://stackoverflow.com/questions/38369565/how-to-get-learning-rate-or-iteration-times-when-define ...
- IGMP协议
IGMP报文格式: 4bit的IGMP版本(1)+4bit的IGMP类型(1-2)+8bit未用+16bit检验和(同ICMP)+32bit组地址(D类IP地址) 类型为1说明是由多播路由器发出的查询 ...