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窗体的结构.随着系统功能的扩充,不断有新的子系统加入系统中,单个工程会变得非常大,每次做一点修改都要重新编译,单个 ...
随机推荐
- FFmpeg制作+x264+faac
https://blog.csdn.net/leixiaohua1020/article/details/47071547 雷神的博客 https://www.jianshu.com/p/3f023 ...
- angular 上传图像的使用总结
AngularJS 的文件上传控件有两个:(1) angular-file-upload:https://github.com/nervgh/angular-file-upload(2) ng-fil ...
- [DPI][TCP] linux API的接口如何控制urgent包的收发
做DPI,写协议栈的时候,处理到了urgent数据包.突然好奇应用层是如何控制发出urgent包的呢?而接收端又是如何知道,接受到了urgent包的呢? man 7 tcp,中有如下一段: TCP s ...
- 安装多个java后,java版本不对
参考资料: https://www.cnblogs.com/Kidezyq/p/5781131.html 主要原因是javac -version是由JAVA_HOME指定的路径中的java版本来决定的 ...
- ios APP改名推送名字还是旧的
重启手机就行了 https://community.jiguang.cn/t/ios-app/14759
- flex布局 响应式布局
移动端页面开发流程 移动端页面布局 一.移动端app分类 1.Native App原生app手机应用程序 使用原生的语言开发的手机应用,Android系统用的是java,ios系统用的是objec ...
- es中对mapping的理解
(1)往es里面直接插入数据,es会自动建立索引,同时建立type以及对应的mapping (2)mapping中就自动定义了每个field的数据类型 (3)不同的数据类型(比如说text和date) ...
- es分布式文档系统_bulk api的奇特json格式与底层性能优化关系
1.bulk api奇特的json格式{"action":{"meta"}}\n{"data"}\n{"action": ...
- oracle的undo表空间
undo表空间是Oracle特有的概念.undo表空间中会自动分配undo段,这些undo段用来保存事务中的DML语句的undo信息,也就是来保存数据在被修改之前的值.在rollback,实例恢复(回 ...
- 生成器-代码举例:()和yield
怎么自定义一个生成器:两个方法: 1.小括号包裹表达式 2.函数中用yield返回 方法一:①小括号包裹表达式 G=(x*2 for x in range(5)) print(G)输出:<gen ...