📄 commonmethods.java
字号:
/**
* @(#)CommonMethods.java 2003/03/18
*
* Copyright (c) 2000-2003 Wuhan Tianyu Information Industry,Inc.
* All rights reserved.
*/
package mybean;
import java.util.*;
import java.io.*;
import java.nio.*;
import java.nio.ByteBuffer;
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
public class CommonMethods
{
/**
* 从指定文件fileName中读取key的值,若不存在返回空串""
*/
public static String readIniFile(String fileName, String key)
{
try
{
FileInputStream fs = new FileInputStream(fileName);
Properties config = new Properties();
config.load(fs);
fs.close();
String ret =config.getProperty(key);
if(ret == null)
return "";
return ret;
}
catch(Exception ex)
{
return "";
}
}
public static int writeIniFile(String fileName, String key, String value)
{
try
{
File file = new File(fileName);
if (file.exists() == false)
throw(new Exception("File not found."));
int dataLen =(int)file.length();
byte[] fileData = new byte[dataLen];
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(fileData);
inputStream.close();
String fileString = new String(fileData);
key = "\r\n" + key;
int offset;
offset = fileString.indexOf(key + " ");
if (offset == -1)
{
offset = fileString.indexOf(key + "=");
if (offset == -1) throw(new Exception("Key not found."));
}
int endPos;
endPos = fileString.indexOf("\r\n", offset + 1);
if (endPos == -1) throw(new Exception("Key not found."));
String line = key + " = " + value;
fileString = fileString.substring(0, offset) + line + fileString.substring(endPos);
fileData = fileString.getBytes();
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(fileData, 0, fileData.length);
outputStream.close();
return 0;
}
catch(Exception ex)
{
return -1;
}
}
public static String getConfigString(String strKey)
{
try
{
String strFileName = (String)(System.getProperties().get("user.dir"))+ File.separatorChar + "ypc.ini";
return (readIniFile(strFileName, strKey));
}
catch (Exception ex)
{
return "";
}
}
public static boolean setConfigString(String strKey,String value)
{
try
{
String strFileName = (String)(System.getProperties().get("user.dir"))+ File.separatorChar + "ypc.ini";
if(writeIniFile(strFileName,strKey,value) == 0)
return true;
else
return false;
}
catch(Exception e)
{
return false;
}
}
public static void debugMessage(String msg)
{
System.out.print("["+Thread.currentThread().getName()+"]\t[运行]" +msg+ "\r\n");
}
public static void main(String[] arg)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -