📄 hitcounter.java
字号:
package jesse3647.servlet;
import java.io.*;
public class HitCounter
{
public String getHitCounter(String counterFile) throws IOException
{
String counterString;
int secondDigit;
//Creates a FileInput object and stores number count into count variable
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(counterFile)));
int count = in.readInt();
in.close();
//Pulls out the second digit from the counter and stores it
secondDigit = count / 10;
secondDigit = secondDigit % 10;
switch (count % 10)
{
case 1: if(secondDigit == 1)
{
counterString = count + "th";
break;
}
else
{
counterString = count + "st";
break;
}
case 2: if(secondDigit == 1)
{
counterString = count + "th";
break;
}
else
{
counterString = count + "nd";
break;
}
case 3: if(secondDigit == 1)
{
counterString = count + "th";
break;
}
else
{
counterString = count + "rd";
break;
}
default: counterString = count + "th";
break;
}
//Creates FileOutPut object, increaments counter, and counter number in file
DataOutputStream out1 = new DataOutputStream((new FileOutputStream(counterFile)));
out1.writeInt(count + 1);
out1.close();
//Returns counter
return counterString;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -