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配置文件的创建和读取的更多相关文章

  1. SpringBoot中yml配置文件

    1.yml配置文件书写格式 格式是在普通配置文件中以“.”分割的属性名称,该为“: ”和换行. 例子: //普通格式 spring.datasource.driver-class-name=com.m ...

  2. Spring Boot中yml配置文件Map集合注入及使用方式

    yml配置文件 maps: "{key1: 'value1', key2: 'value2'}" java中 @Value("#{${maps}}") priv ...

  3. Spring Boot 中yml配置文件

    步骤一:yml格式 现在大家发现,在springboot里还是要用到配置文件的. 除了使用.properties外,springboot还支持 yml格式. 个人觉得yml格式的可读性和..prope ...

  4. Bukkit插件编程之检测玩家受到的伤害是来自投射类武器还是近身武器

    package com.sklm.lhb.listener; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; impo ...

  5. 《python核心编程》笔记——文件的创建、读取和显示

    创建文件(makeTextFile.py)脚本提醒用户输入一个尚不存在的文件名,然后由用户输入文件每一行,最后将所有文本写入文本文件 #!/usr/bin/env python 'makeTextFi ...

  6. jsp中excel文件的创建与读取

    1.创建excel文件//这里的jxl不是java的标准jar包,需要在项目中另外加载 import jxl.Workbook; import jxl.write.Label; import jxl. ...

  7. (蓝牙)网络编程中,使用InputStream read方法读取数据阻塞的解决方法

    问题如题,这个问题困扰了我好几天,今天终于解决了,感谢[1]. 首先,我要做的是android手机和电脑进行蓝牙通信,android发一句话,电脑端程序至少就要做到接受到那句话.android端发送信 ...

  8. Qt多线程编程中的对象线程与函数执行线程

    近来用Qt编写一段多线程的TcpSocket通信程序,被其中Qt中报的几个warning搞晕了,一会儿是说“Cannot create children for a parent that is in ...

  9. 初探Delphi中的插件编程

    前言 我写Delphi程序是从MIS系统入门的,开始尝试子系统划分的时候采用的是MDI窗体的结构.随着系统功能的扩充,不断有新的子系统加入系统中,单个工程会变得非常大,每次做一点修改都要重新编译,单个 ...

随机推荐

  1. 安装MAC的ReactNative环境

    brew install node brew install watchman npm config set registry https://registry.npm.taobao.org --gl ...

  2. mac休眠掉电快,更改休眠模式

    打开终端输入: $ pmset -g 查看休眠模式 hibernatemode 发现值为3, 这是大多数的设置,如果为0 ,那么休眠时严重掉电, 我们可以改变这个模式: $ sudo pmset -a ...

  3. HTTP缓存机制及原理

    前言 Http 缓存机制作为 web 性能优化的重要手段,对于从事 Web 开发的同学们来说,应该是知识体系库中的一个基础环节,同时对于有志成为前端架构师的同学来说是必备的知识技能.但是对于很多前端同 ...

  4. block diagonal matrix 直和 块对角矩阵 不完美 有缺陷 缩放 射影几何

    小结: 1.block diagonal matrix  直和 块对角矩阵 A block diagonal matrix is a block matrix that is a square mat ...

  5. [qemu][cloud][centos][ovs][sdn] centos7安装高版本的qemu 以及 virtio/vhost/vhost-user咋回事

    因为要搭建ovs-dpdk,所以需要vhost-user的qemu centos默认的qemu与qemu-kvm都不支持vhost-user,qemu最高版本是2.0.0, qemu-kvm最高版本是 ...

  6. [hardware][intel] intel全系列网卡调研

    除了公司用,我自己还要买一块家用. 但是在这一切开始之前,还需要搞清楚PCIE到底咋回事. 一, 总线 https://zh.wikipedia.org/wiki/%E6%80%BB%E7%BA%BF ...

  7. python 冷知识

    nohup python robot.py nohup python -u robot.py > robot.log 2>&1 & -u 就是指定实时的日志输出目录,而 & ...

  8. LeetCode 883 Projection Area of 3D Shapes 解题报告

    题目要求 On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes. ...

  9. Kubernetes应用管理

    除了容器资源管理和调度,Kubernetes另外一个核心价值是提供了针对不同类型应用管理的API接口集合,这些API集合把针对不同类型应用的管理能力分别到Kubernetes平台中.以Web业务(Lo ...

  10. “我的小程序”来了 新版微信v6.7.1下拉就能找到

    今天iOS版微信迎来v6.7.1正式版发布,本次升级主要是可以把常用的小程序添加到“我的小程序”.近期版本微信可以直接浏览订阅号的消息,扫一扫可拍照翻译整页中英文,浏览的文章支持缩小为浮窗.两大更新如 ...