package gdbye.com.io;
import java.io.*;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import java.lang.*;
import gdbye.com.basice.*;//一个用于处理字符等基本的类BaseCount
import gdbye.com.date.newCom.*;
import com.ntsky.file.FileUtil;//一个文件上传的类,我这里主要用来生成目录,有需要的联系
public class IOElse{
/*
本人生手程序写得太乱连我自己也看晕了!!!!有问题请联系
gdbye.com.<--这包是我的类
*/
private Map map = new HashMap();
private String root_jsp = "";
private String FileNameRet = "";
private String FIleNmae = "";
private String NameFirst = "";
private String MuFile_root = "";
private String Class_root = "";
private String SetFileRom = "";
private boolean creatFile = false;
private String FullMUFile_root = "";
private ArrayList PostList = null;
public void IOElse_Map(int replaceInt,String Outleft) {
try{
BaseCount b = new BaseCount();
for(int i = 1; i <= replaceInt; i++){
if(i<=9)
map.put(NameFirst + "0" + i + Outleft,b.convert((String)PostList.get(i-1)));
else
map.put(NameFirst + i + Outleft,b.convert((String)PostList.get(i-1)));
}
}catch(Exception e){
e.printStackTrace();
return;
}
}
public void setArrayList(ArrayList stN){
this.PostList = stN;
}
/*
初始化变量
SetRepalceName:要查找的对象开始段
Souse_setFileName:模版的文件名
MubilSetFileName:生成的文件名
MubilSetFileRoot:文件生成的路径
initialize:取得跟目录路径
GetAutoFileName(str,endst):跟据str头生成新文件名以endst结尾
*/
public void SetRepalceName(String str){
this.NameFirst = str;
}
public void SetClass_root(String Str){
this.Class_root = Str;
}
public void Souse_setFileName(String File_Name){
this.FileNameRet = File_Name;
}
public void MubilSetFileName(String File_Name){
this.FIleNmae = File_Name;
}
public void MubilSetFileRoot(String strRoot){
BaseCount b = new BaseCount();
if(b.EmptyStr(strRoot))
this.MuFile_root = Class_root + strRoot;
else{
GregorianCalendar d = new GregorianCalendar();
this.MuFile_root = Class_root + d.get(Calendar.YEAR) +"-"+ (d.get(Calendar.MONTH)+1) +"-"+ d.get(Calendar.DAY_OF_MONTH);
}
}
public void initialize(String url) {
this.root_jsp = url;
}
public void initialize(PageContext pageContext){
this.root_jsp = pageContext.getServletContext().getRealPath("/");
}
public String GetAutoFileName(String start,String Endstr){
GregorianCalendar d = new GregorianCalendar();
return start+ "_" + d.get(Calendar.YEAR)+
(d.get(Calendar.MONTH)+1) + d.get(Calendar.DAY_OF_MONTH)+
d.get(Calendar.HOUR)+
d.get(Calendar.MINUTE)+
d.get(Calendar.SECOND)+
"." + Endstr;
}
/*
返回数据
get_MubilSetFileName:返回生成文件名
get_MubilSetFileName:返回文件路径
getSetFileRom:返回生成文件的内容
*/
public String get_MubilSetFileName(){
return this.FIleNmae;
}
public String get_MubilSetFileRoot(){
return this.MuFile_root;
}
public String getSetFileRom(){
return this.SetFileRom;
}
public String sour_file(){
return root_jsp + FileNameRet;
}
public String get_FullMUFile_root(){
return FullMUFile_root;
}
public String get_Full_root_FileName(){
String Fild_D = MuFile_root;
if(!MuFile_root.endsWith("/"))
Fild_D += "/";
return Fild_D + get_MubilSetFileName();
}
/*
生成内容
*/
public boolean TextSubcut(){
try{
boolean return_fun = true;
String FileName = root_jsp + FileNameRet;
BaseCount a = new BaseCount();
String FileRom = "";
File myFile = new File(FileName);
String temp = "";
if(myFile.exists()){
InputStreamReader in = new InputStreamReader(new FileInputStream(myFile),"GB2312");
BufferedReader br = new BufferedReader(in);
temp = br.readLine();
int tempInt = 0;
int tempOut = 0;
while(temp != null){
tempInt = temp.indexOf(NameFirst,tempInt);
while(tempInt != -1){
FileRom += temp.substring(tempOut,tempInt) + getString(temp.substring(tempInt,tempInt + NameFirst.length()+3));
tempOut = tempInt + NameFirst.length() + 3;
if(tempOut >= temp.length()){
tempInt = -1;
}else
tempInt = temp.indexOf(NameFirst,tempOut);
}
if(tempOut <= temp.length())
FileRom += temp.substring(tempOut) + "/n";
else
FileRom += "/n";
tempInt = 0;
tempOut = 0;
temp = br.readLine();
}
br.close();
}else{
return_fun = false;
}
this.SetFileRom = FileRom;
return return_fun;
}catch(IOException e){
System.out.println(e.getMessage());
return false;
}
}
/*
生成文件
*/
public void CreatFile(){
try{
FileOutputStream fos = new FileOutputStream(FullMUFile_root + FIleNmae);
Writer out = new OutputStreamWriter(fos,"GB2312");
out.write(SetFileRom);
out.close();
fos.close();
this.creatFile = true;
}catch(IOException e){
System.out.println(e.getMessage());
}
}
public void Creatdir(){
try{
GregorianCalendar d = new GregorianCalendar();
FileUtil c = new FileUtil();
String Fild_D = MuFile_root;
if(!MuFile_root.endsWith("/"))
Fild_D += "/";
//if()
//Fild_D += d.get(Calendar.YEAR) + "-" + d.get(Calendar.MONTH) + "-" + d.get(Calendar.DAY_OF_MONTH);
c.makeDir(Fild_D,root_jsp);
this.FullMUFile_root = root_jsp + Fild_D;
}catch(Exception e){
}
}
public Map getInputMap() {
return this.map;
}
public String getString(String key) {
// TODO 自动生成方法存根
return (String)map.get(key);
}
}