package com.demo;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ShowLoginTimesServlet extends HttpServlet {
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
int count = 0;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
File file = new File("D:/count.txt");
if (!file.exists()) {
file.createNewFile();
}
if (file.length() > 0) {
DataInputStream dis = new DataInputStream(new FileInputStream(file));
count = dis.readInt();
dis.close();
} else {
count = 1;
}
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
dos.writeInt(count+1); dos.close();
}
}
为什么count的值在count.txt文件里没有显示出来呢
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ShowLoginTimesServlet extends HttpServlet {
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
int count = 0;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
File file = new File("D:/count.txt");
if (!file.exists()) {
file.createNewFile();
}
if (file.length() > 0) {
DataInputStream dis = new DataInputStream(new FileInputStream(file));
count = dis.readInt();
dis.close();
} else {
count = 1;
}
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
dos.writeInt(count+1); dos.close();
}
}
为什么count的值在count.txt文件里没有显示出来呢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货