用于控制java.io.tmpdir的环境变量?

时间:2022-03-04 22:46:26

I've used the TMP environment variable to control things like where gcc writes it's temporary files, but I can't seem to find an equivalent for java's createTempFile API.

我已经使用TMP环境变量来控制gcc写入临时文件的地方,但我似乎找不到java的createTempFile API的等价物。

Does such an environment variable exist?

这样的环境变量是否存在?

7 个解决方案

#1


104  

Hmmm -- since this is handled by the JVM, I delved into the OpenJDK VM source code a little bit, thinking that maybe what's done by OpenJDK mimics what's done by Java 6 and prior. It isn't reassuring that there's a way to do this other than on Windows.

嗯 - 由于这是由JVM处理的,我稍微深入研究了OpenJDK VM源代码,认为OpenJDK可能做的是模仿Java 6及之前所做的事情。除了Windows之外,还有一种方法可以做到这一点。

On Windows, OpenJDK's get_temp_directory() function makes a Win32 API call to GetTempPath(); this is how on Windows, Java reflects the value of the TMP environment variable.

在Windows上,OpenJDK的get_temp_directory()函数对GetTempPath()进行Win32 API调用;这就是在Windows上,Java反映了TMP环境变量的价值。

On Linux and Solaris, the same get_temp_directory() functions return a static value of /tmp/.

在Linux和Solaris上,相同的get_temp_directory()函数返回静态值/ tmp /。

I don't know if the actual JDK6 follows these exact conventions, but by the behavior on each of the listed platforms, it seems like they do.

我不知道实际的JDK6是否遵循这些确切的约定,但是通过每个列出的平台上的行为,它们似乎都是这样。

#2


89  

According to the java.io.File Java Docs

根据java.io.File Java Docs

The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.

缺省临时文件目录由系统属性java.io.tmpdir指定。在UNIX系统上,此属性的默认值通常为“/ tmp”或“/ var / tmp”;在Microsoft Windows系统上,它通常是“c:\ temp”。调用Java虚拟机时,可以为此系统属性提供不同的值,但不保证对此属性的编程更改会对此方法使用的临时目录产生任何影响。

To specify the java.io.tmpdir System property, you can invoke the JVM as follows:

要指定java.io.tmpdir System属性,可以按如下方式调用JVM:

java -Djava.io.tmpdir=/path/to/tmpdir

By default this value should come from the TMP environment variable on Windows systems

默认情况下,此值应来自Windows系统上的TMP环境变量

#3


50  

You could set your _JAVA_OPTIONS environmental variable. For example in bash this would do the trick:

您可以设置_JAVA_OPTIONS环境变量。例如在bash中,这可以解决问题:

export _JAVA_OPTIONS=-Djava.io.tmpdir=/new/tmp/dir

I put that into my bash login script and it seems to do the trick.

我把它放到我的bash登录脚本中,似乎可以解决这个问题。

#4


32  

Use

使用

$ java -XshowSettings
Property settings:
    java.home = /home/nisar/javadev/javasuncom/jdk1.7.0_17/jre
    java.io.tmpdir = /tmp

#5


23  

It isn't an environment variable, but still gives you control over the temp dir:

它不是环境变量,但仍然可以控制temp目录:

-Djava.io.tmpdir

ex.:

例:

java -Djava.io.tmpdir=/mytempdir

#6


13  

To be clear about what is going on here:

要清楚这里发生了什么:

  • The recommended way to set the temporary directory location is to set the System property called "java.io.tmpdir", e.g. by giving the option -Djava.io.tmpdir=/mytempdir to the java command. The property can also be changed from within a program by calling System.setProperty("java.io.tmpdir", "/mytempdir) ... modulo sandbox security issues.

    设置临时目录位置的推荐方法是设置名为“java.io.tmpdir”的System属性,例如,通过向java命令提供选项-Djava.io.tmpdir = / mytempdir。也可以通过调用System.setProperty(“java.io.tmpdir”,“/ mytempdir)... modulo沙箱安全问题从程序中更改属性。

  • If you don't explicitly set the "java.io.tmpdir" property on startup, the JVM initializes it to a platform specific default value. For Windows, the default is obtained by a call to a Win32 API method. For Linux / Solaris the default is apparently hard-wired. For other JVMs it could be something else.

    如果未在启动时显式设置“java.io.tmpdir”属性,则JVM会将其初始化为特定于平台的默认值。对于Windows,默认值是通过调用Win32 API方法获得的。对于Linux / Solaris,默认显然是硬连线的。对于其他JVM,它可能是其他东西。

Empirically, the "TMP" environment variable works on Windows (with current JVMs), but not on other platforms. If you care about portability you should explicitly set the system property.

根据经验,“TMP”环境变量适用于Windows(使用当前JVM),但不适用于其他平台。如果您关心可移植性,则应明确设置系统属性。

#7


-1  

Use below command on UNIX terminal :

在UNIX终端上使用以下命令:

java -XshowSettings

This will display all java properties and system settings. In this look for java.io.tmpdir value.

这将显示所有java属性和系统设置。在此查找java.io.tmpdir值。

#1


104  

Hmmm -- since this is handled by the JVM, I delved into the OpenJDK VM source code a little bit, thinking that maybe what's done by OpenJDK mimics what's done by Java 6 and prior. It isn't reassuring that there's a way to do this other than on Windows.

嗯 - 由于这是由JVM处理的,我稍微深入研究了OpenJDK VM源代码,认为OpenJDK可能做的是模仿Java 6及之前所做的事情。除了Windows之外,还有一种方法可以做到这一点。

On Windows, OpenJDK's get_temp_directory() function makes a Win32 API call to GetTempPath(); this is how on Windows, Java reflects the value of the TMP environment variable.

在Windows上,OpenJDK的get_temp_directory()函数对GetTempPath()进行Win32 API调用;这就是在Windows上,Java反映了TMP环境变量的价值。

On Linux and Solaris, the same get_temp_directory() functions return a static value of /tmp/.

在Linux和Solaris上,相同的get_temp_directory()函数返回静态值/ tmp /。

I don't know if the actual JDK6 follows these exact conventions, but by the behavior on each of the listed platforms, it seems like they do.

我不知道实际的JDK6是否遵循这些确切的约定,但是通过每个列出的平台上的行为,它们似乎都是这样。

#2


89  

According to the java.io.File Java Docs

根据java.io.File Java Docs

The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.

缺省临时文件目录由系统属性java.io.tmpdir指定。在UNIX系统上,此属性的默认值通常为“/ tmp”或“/ var / tmp”;在Microsoft Windows系统上,它通常是“c:\ temp”。调用Java虚拟机时,可以为此系统属性提供不同的值,但不保证对此属性的编程更改会对此方法使用的临时目录产生任何影响。

To specify the java.io.tmpdir System property, you can invoke the JVM as follows:

要指定java.io.tmpdir System属性,可以按如下方式调用JVM:

java -Djava.io.tmpdir=/path/to/tmpdir

By default this value should come from the TMP environment variable on Windows systems

默认情况下,此值应来自Windows系统上的TMP环境变量

#3


50  

You could set your _JAVA_OPTIONS environmental variable. For example in bash this would do the trick:

您可以设置_JAVA_OPTIONS环境变量。例如在bash中,这可以解决问题:

export _JAVA_OPTIONS=-Djava.io.tmpdir=/new/tmp/dir

I put that into my bash login script and it seems to do the trick.

我把它放到我的bash登录脚本中,似乎可以解决这个问题。

#4


32  

Use

使用

$ java -XshowSettings
Property settings:
    java.home = /home/nisar/javadev/javasuncom/jdk1.7.0_17/jre
    java.io.tmpdir = /tmp

#5


23  

It isn't an environment variable, but still gives you control over the temp dir:

它不是环境变量,但仍然可以控制temp目录:

-Djava.io.tmpdir

ex.:

例:

java -Djava.io.tmpdir=/mytempdir

#6


13  

To be clear about what is going on here:

要清楚这里发生了什么:

  • The recommended way to set the temporary directory location is to set the System property called "java.io.tmpdir", e.g. by giving the option -Djava.io.tmpdir=/mytempdir to the java command. The property can also be changed from within a program by calling System.setProperty("java.io.tmpdir", "/mytempdir) ... modulo sandbox security issues.

    设置临时目录位置的推荐方法是设置名为“java.io.tmpdir”的System属性,例如,通过向java命令提供选项-Djava.io.tmpdir = / mytempdir。也可以通过调用System.setProperty(“java.io.tmpdir”,“/ mytempdir)... modulo沙箱安全问题从程序中更改属性。

  • If you don't explicitly set the "java.io.tmpdir" property on startup, the JVM initializes it to a platform specific default value. For Windows, the default is obtained by a call to a Win32 API method. For Linux / Solaris the default is apparently hard-wired. For other JVMs it could be something else.

    如果未在启动时显式设置“java.io.tmpdir”属性,则JVM会将其初始化为特定于平台的默认值。对于Windows,默认值是通过调用Win32 API方法获得的。对于Linux / Solaris,默认显然是硬连线的。对于其他JVM,它可能是其他东西。

Empirically, the "TMP" environment variable works on Windows (with current JVMs), but not on other platforms. If you care about portability you should explicitly set the system property.

根据经验,“TMP”环境变量适用于Windows(使用当前JVM),但不适用于其他平台。如果您关心可移植性,则应明确设置系统属性。

#7


-1  

Use below command on UNIX terminal :

在UNIX终端上使用以下命令:

java -XshowSettings

This will display all java properties and system settings. In this look for java.io.tmpdir value.

这将显示所有java属性和系统设置。在此查找java.io.tmpdir值。