Windows临时目录详细信息(Java) [英] Windows temp directory details (Java)

查看:342
本文介绍了Windows临时目录详细信息(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个需要一个通用临时文件夹的程序。我试图找到有关Windows Temp文件夹的详细信息。有两个我知道的路径 -


  1. 在AppData\Local\Temp\ $ b下的每个用户目录$ b这可能会根据Windows版本而改变吗?

  2. 在Temp \(C:\Windows\Temp)下的系统文件夹中

  3. / li>

我想知道Windows究竟是干什么的。如果Windows从任一位置删除文件,它是什么时候执行的?编辑:我有一个更大的问题,实际上 - 因为某些引擎我间接地运行我的程序,所以我应该如何使用这些目录我的编程?它使用我在临时目录中创建的文件,我需要一个不使用路径中的空白字符的临时目录。 Windows上的Java的System.getProperty(java.io.tmpdir)给了我在用户目录下的临时文件,在XP下是在文件和设置...
不好。有什么建议么?这就是为什么我想知道C:\ Windows \ Temp \目录...

解决方案

。有一个用户和系统文件夹,其默认位置根据Windows版本,系统文件夹名称而有所不同,事实上,在旧版本的Windows中,用户和系统的情况都是一样的。但是,这些默认设置可能会被覆盖(它们在我现在使用的系统上,它们不在系统文件夹的同一个驱动器上)。



位置存储在系统变量中。一些框架(.NET,VB6,毫无疑问是其他)为您提供了便捷的方法来查找路径,而不必查找系统变量(例如.NET中的System.IO.Path.GetTempPath)。

Windows并没有为你清理临时文件夹(这就是为什么在你自己的机器上每隔几个月就要刷新一次旧文件的原因),这是你自己玩的好。创建一个文件或文件不太可能使用任何其他软件正在使用的名称(他们应该小心地做同样的事情,所以任何名字都应该这样做,但假设系统上的其他代码更糟)总是好的, (或至少在应用程序退出时)删除文件。



在.NET System.IO.Path.GetTempFileName()中将创建一个新的文件温度区域,并将其名称返回给您,这是合理保证不与他人冲突,所以使用该方法或类似的方法,如果可以的话。


I'm writing a program that needs a generic temp folder. I'm trying to find details about the Windows Temp folders. There are two paths that I know about -

  1. In each user directory under AppData\Local\Temp\ This may change depending Windows version?

  2. In the system folder under Temp\ (C:\Windows\Temp)

I'm wondering exactly what Windows does to each of these. If Windows deletes files from either location, when does it do so? How can/should I use these directories for my programming?

EDIT: I have a bigger problem actually - Because of a certain engine I'm running indirectly with my program, which uses files I'm creating in a temp directory, I need a temp directory that doesn't use whitespace characters in the path. Java's System.getProperty("java.io.tmpdir") on Windows gives me the temp that's in the user directory, which on XP is under "Documents and Settings..." Not good. Any suggestions? This is why I'm wondering about the C:\Windows\Temp\ directory...

解决方案

Not quite. There is a user and system folder, the default location of which varies according the windows version, system folder name, and indeed in older versions of windows was the same for both the user and system case. However, these defaults can be over-ridden (they are on the system I'm using now, where they aren't on the same drive as the system folder).

The locations are stored in system variables. Some frameworks (.NET, VB6 and no doubt others) give you convient ways to find the paths rather than having to look up the system variable (e.g. System.IO.Path.GetTempPath in .NET).

Windows does not clean up the temporary folder for you (which is why it's worth blasting out old files it every few months on your own machine), it's up to you to play nice. Create a file or files unlikely to step on the names any other software is using (they should take care to do the same, and so any name should do, but it's always good to assume the worse of other code on the system), and delete files when you're done (or on application exit at least).

In .NET System.IO.Path.GetTempFileName() will create a new file in the temp area and return the name of it to you, that is reasonably guaranteed not to conflict with others' so use that or similar methods if you can.

这篇关于Windows临时目录详细信息(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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