临时文件名有奇怪的数字 [英] Temporary File Name has weird numbers

查看:117
本文介绍了临时文件名有奇怪的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我写了一个代码来创建一个具有特定名称和扩展名为.txt的临时文件

So i wrote a code to create a temporary file with a specific name and with the .txt extension

File f=File.createTempFile("LoginStatus",".txt",new File("/Users/Alex/Desktop"));



我去检查了文件.我看到前缀之后有一个随机数字序列,后跟文件扩展名..

有人可以帮忙吗:)

*请注意,我不是专业人士,因此请承担使其变得尽可能简单的痛苦

谢谢:)



I went to check out the file. I see that after the prefix it has a random series of numbers, followed by the file extension..

Could someone please help :)

*Take note, i''m not a professional, so please bear the pain of making it as simple as possible

Thanks :)

推荐答案

那是一个临时文件,应该是唯一的名称,仅供临时使用-通常少于应用程序的生命周期.

您想保留一些"LoginStatus".这意味着什么?里面有什么?

我建议为此做一个外观或将数据存储在属性列表中.
当应用程序结束时,两者都将被销毁,数据不得写入磁盘,因此非常安全.

但是请告诉我们您要存储的内容.

简单代码:
该应用程序拥有一个Hashmap,用于存储当前状态,并设置为枚举以使其易于使用.可以安全设置.

这是非常基本的信息,有关更多信息,我建议创建一个在正面存储一个员工数据的对象.
That''s a temporary file, that one is supposed to be unique named and is just for temporary use - normally less then an application''s life cycle.

You want to hold some "LoginStatus". What does that mean? what is in there?

I would recommend to make a facade for that or to store the data in a property list.
Both will be destroyed when the application is ending, data must not be written to disc, so it''s pretty safe.

But please tell us what you want to store.

Simple Code:
The application holds a Hashmap, which stores the current status, set as a enum to make it easy & safe for setting.

This is very basic, for more information I''d recommend to create an Object holding one employee''s data in a facade.
import java.util.HashMap;

public class Application {
	public enum STATUS {
		IN, OUT
	}
	private HashMap<String, STATUS> oMap = new HashMap<String, STATUS>();

	public Application(){
		setStatus("Alex", STATUS.IN);
		setStatus("John", STATUS.IN);
		setStatus("Jack", STATUS.IN);
		
		showStatus();
		// change
		setStatus("Alex", STATUS.OUT);
		
		showStatus();
	}
	
	private void showStatus() {
		for (String strValue : oMap.keySet()) { 
			System.out.println("The Employee " + strValue + " is " + oMap.get(strValue));
		}
		System.out.println(); // empty line for better reading
	}

	// status is updated or added automatically to the map
	private void setStatus(String strName, STATUS oState){
		oMap.put(strName, oState);
	}

	public static void main(String[] args) {
		// start app
		Application oApp = new Application();
	}
}


这篇关于临时文件名有奇怪的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆