如何将存储在文件夹/文本文件中的值存储在头文件中,并在不使用外部存储器或驱动器的情况下将其再次导入程序
每次运行它并将值存储在文件中时,此代码都会给出一个递增的值。但我需要将文本文件存储在标头本身而不是驱动器/外部存储器中。那么我们是否有任何可以使用它而不是驱动器的存储头
class Test {
public static void main(String[] args) {
Test test1 = new Test();
test1.doMethod();
}
public int getCount() {
int count = 0;
try {
if (!new File("d:\\myCount.txt").exists())
return 1;
else {
BufferedReader br = new BufferedReader(new FileReader(new File("d:\\myCount.txt")));
String s = br.readLine();
count = Integer.parseInt(s);
br.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return count;
}
public void putCount(int count) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("d:\\myCount.txt")));
bw.write(Integer.toString(count));
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void doMethod() //Put Method//
{
int count = getCount();
if (count < 10000) {
NumberFormat nf = new DecimalFormat("0000");
System.out.println(" ID:" + nf.format(count));
count++;
putCount(count);
} else if (count >= 10000)
System.out.print("NO VACCANCY");
}
}