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

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

问题描述

我正在编写一个需要通用临时文件夹的程序.我正在尝试查找有关 Windows Temp 文件夹的详细信息.我知道有两条路径 -

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. 在 AppDataLocalTemp 下的每个用户目录中这可能会因 Windows 版本而异?

  1. In each user directory under AppDataLocalTemp This may change depending Windows version?

在Temp(C:WindowsTemp)下的系统文件夹

In the system folder under Temp (C:WindowsTemp)

我想知道 Windows 对其中的每一个都做了什么.如果 Windows 从任一位置删除文件,它何时删除?我可以/应该如何将这些目录用于我的编程?

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?

实际上我有一个更大的问题 - 由于我的程序间接运行某个引擎,它使用我在临时目录中创建的文件,我需要一个不使用空格字符的临时目录在路径中.Windows 上的 Java 的 System.getProperty("java.io.tmpdir") 为我提供了用户目录中的临时文件,在 XP 上该目录位于文档和设置..."下不好.有什么建议?这就是为什么我想知道 C:WindowsTemp 目录...

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:WindowsTemp directory...

推荐答案

不太清楚.有一个用户和系统文件夹,其默认位置根据 Windows 版本、系统文件夹名称而有所不同,实际上在旧版本的 Windows 中,用户和系统案例都是相同的.但是,这些默认值可以被覆盖(它们在我现在使用的系统上,它们与系统文件夹不在同一个驱动器上).

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).

位置存储在系统变量中.某些框架(.NET、VB6 以及其他框架)为您提供了查找路径的便捷方法,而不必查找系统变量(例如 .NET 中的 System.IO.Path.GetTempPath).

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 不会为您清理临时文件夹(这就是为什么每隔几个月在您自己的机器上清理旧文件是值得的),这取决于您是否玩得开心.创建一个或多个文件,它们不太可能使用任何其他软件正在使用的名称(他们应该注意这样做,因此任何名称都应该这样做,但假设系统上其他代码的更糟总是好的),并且完成后(或至少在应用程序退出时)删除文件.

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).

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

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天全站免登陆