bug
This commit is contained in:
@@ -3,43 +3,22 @@ package sc545.pay.utils;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class ReadTxt {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
//上月新增访客
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int month = cal.get(Calendar.MONTH);
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
if(month==0){
|
||||
month=12;
|
||||
year=year-1;
|
||||
}
|
||||
String ms = String.format("%02d", month);
|
||||
String ys = String.format("%04d", year);
|
||||
|
||||
String smm=ys+"-"+ms;
|
||||
String smck= ReadTxt.getSetting(null, "count.ini",smm, "0");
|
||||
|
||||
String a = ReadTxt.getSetting(null, "setting.ini", "pageNullTelTxt","提交需求");
|
||||
System.out.println(a+smm+"\n"+ms+"\n"+ys);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 按行读取txt文件
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\开头)
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @return ArrayList 返回每行数据为一个items的集合
|
||||
*/
|
||||
public static ArrayList<String> readFileLine(ServletContext servletContext, String path) {
|
||||
@@ -49,7 +28,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -82,55 +61,12 @@ public class ReadTxt {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 按行读取文件
|
||||
* debug模式
|
||||
* @param path
|
||||
* 文件地址(默认D:\\开头)
|
||||
* @return ArrayList 返回每行数据为一个items的集合
|
||||
*/
|
||||
public static ArrayList<String> readFileLineDEBUG(String path) {
|
||||
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
//debug模式下把所有路径改为tomcat下的真实路径
|
||||
if(path.indexOf("/")==0){
|
||||
String tomcat_path = "D:/java/Tomcat_8.5.23/webapps/ROOT";
|
||||
path =tomcat_path+path;
|
||||
}
|
||||
|
||||
ArrayList<String> strarr = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
strarr = new ArrayList<String>();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
|
||||
strarr.add(lineTxt);
|
||||
}
|
||||
|
||||
read.close();
|
||||
} else {
|
||||
strarr = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return strarr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写入txt文档,已存在就修改,否则写入末尾,自动加换行 (文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\开头)
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @param keyname
|
||||
* 要修改的参数名
|
||||
* @param content
|
||||
@@ -145,7 +81,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -213,7 +149,7 @@ public class ReadTxt {
|
||||
* 读取txt配置,返回map集合(文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\开头)
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @return hashmap
|
||||
*/
|
||||
public static HashMap<String, String> readSetting(ServletContext servletContext, String path) {
|
||||
@@ -222,7 +158,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -268,7 +204,7 @@ public class ReadTxt {
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\开头)
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
*
|
||||
* @param t 只取以此字符开头的,不限制填null
|
||||
* @param st 从以此字符开头的行开始读取,不限制填null
|
||||
@@ -284,7 +220,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -389,7 +325,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -458,7 +394,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -528,7 +464,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
@@ -615,7 +551,7 @@ public class ReadTxt {
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\" + path;
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user