跳到主要內容
/%
//讀取檔案
File txtfile = new File("D://Tomcat/webapps/KCA/count.txt");
StringBuffer result = new StringBuffer();
if (txtfile.exists()) { //檔存在時
InputStreamReader isr = new InputStreamReader(new FileInputStream(txtfile), "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = "";
while((line = br.readLine()) != null){
result.append(line);
}
//out.print(result.toString());
}
%>
/%
int count = 0;
if(result.toString().equals("")){
count = 1;
}else{
count = Integer.valueOf(result.toString()).intValue();
if(count == 0){
count = 1;
}else{
count += 1;
//存入檔案
OutputStream outtxt = new FileOutputStream("D://Tomcat/webapps/KCA/count.txt"); //新增檔案
OutputStreamWriter writer = new OutputStreamWriter(outtxt, "UTF-8");
writer.write(""+count+"");
writer.flush();
writer.close();
}
}
application.setAttribute("count", count);
%>
/%
%>