java.lang.System.getProperty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中java.lang.System.getProperty()方法的一些代码示例,展示了System.getProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.getProperty()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:getProperty

System.getProperty介绍

[英]Returns the value of a particular system property or null if no such property exists.

The following properties are always provided by the Dalvik VM:

NameMeaningExamplefile.separatorjava.io.File#separator/java.class.pathSystem class path.java.class.version(Not useful on Android)50.0java.compiler(Not useful on Android)Emptyjava.ext.dirs(Not useful on Android)Emptyjava.homeLocation of the VM on the file system/systemjava.io.tmpdirSee java.io.File#createTempFile/sdcardjava.library.pathSearch path for JNI libraries/vendor/lib:/system/libjava.vendorHuman-readable VM vendorThe Android Projectjava.vendor.urlURL for VM vendor's web sitehttp://www.android.com/java.version(Not useful on Android)0java.specification.versionVM libraries version0.9java.specification.vendorVM libraries vendorThe Android Projectjava.specification.nameVM libraries nameDalvik Core Libraryjava.vm.versionVM implementation version1.2.0java.vm.vendorVM implementation vendorThe Android Projectjava.vm.nameVM implementation nameDalvikjava.vm.specification.versionVM specification version0.9java.vm.specification.vendorVM specification vendorThe Android Projectjava.vm.specification.nameVM specification nameDalvik Virtual Machine Specificationline.separatorThe system line separator\nos.archOS architecturearmv7los.nameOS (kernel) nameLinuxos.versionOS (kernel) version2.6.32.9-g103d848path.separatorSee java.io.File#pathSeparator:user.dirBase of non-absolute paths/user.home(Not useful on Android)Emptyuser.name(Not useful on Android)Empty

It is a mistake to try to override any of these. Doing so will have unpredictable results.
[中]返回特定系统属性的值,如果不存在此类属性,则返回null。
Dalvik VM始终提供以下属性:
名称含义示例文件。separatorjava。木卫一。文件#分隔符/java。班pathSystem类路径。JAVA班版本(在Android上不可用)50.0java。编译器(在Android上不有用)Emptyjava。ext.dirs(在Android上不有用)Emptyjava。VM在文件系统/systemjava上的主位置。木卫一。tmpdirseeJava。木卫一。文件#createTempFile/sdcardjava。图书馆路径搜索JNI库/vendor/lib:/system/libjava的路径。Vendor人类可读的虚拟机Vendor Android项目Java。小贩虚拟机供应商网站的URLsitehttp://www.android.com/java.version(在Android上不有用)0java。规格版本VM库版本0。9java。规格vendorVM库vendorThe Android Projectjava。规格nameVM库nameDalvik核心库Java。虚拟机。版本VM实现版本1。2.0java。虚拟机。vendorVM实现vendorThe Android Projectjava。虚拟机。nameVM实现nameDalvikjava。虚拟机。规格版本VM规范版本0。9java。虚拟机。规格vendorVM规范vendorThe Android Projectjava。虚拟机。规格nameVM规范nameDalvik虚拟机规范行。separator系统线分隔符\nos.archOS架构ARMV7LOS。nameOS(内核)nameLinuxos。versionOS(内核)version2。6.32.9-G103D848路径。分隔符见java。木卫一。文件#路径分隔符:用户。非绝对路径/用户的dirBase。home(在Android上不可用)Emptyuser。名称(在Android上不可用)为空
试图推翻其中任何一项都是错误的。这样做将产生不可预测的结果。

代码示例

代码示例来源:origin: stackoverflow.com

public class JavaApplication1 {
 public static void main(String[] args) {
    System.out.println("Working Directory = " +
       System.getProperty("user.dir"));
 }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Get the <em>profile value</em> indicated by the specified key from the
 * system properties.
 * @see System#getProperty(String)
 */
@Override
public String get(String key) {
  Assert.hasText(key, "'key' must not be empty");
  return System.getProperty(key);
}

代码示例来源:origin: google/guava

/**
 * Writes the given lines of text to this sink with each line (including the last) terminated with
 * the operating system's default line separator. This method is equivalent to {@code
 * writeLines(lines, System.getProperty("line.separator"))}.
 *
 * @throws IOException if an I/O error occurs while writing to this sink
 * @since 22.0
 */
@Beta
public void writeLines(Stream<? extends CharSequence> lines) throws IOException {
 writeLines(lines, System.getProperty("line.separator"));
}

代码示例来源:origin: google/guava

/**
 * Writes the given lines of text to this sink with each line (including the last) terminated with
 * the operating system's default line separator. This method is equivalent to {@code
 * writeLines(lines, System.getProperty("line.separator"))}.
 *
 * @throws IOException if an I/O error occurs while writing to this sink
 */
public void writeLines(Iterable<? extends CharSequence> lines) throws IOException {
 writeLines(lines, System.getProperty("line.separator"));
}

代码示例来源:origin: google/guava

/**
 * Returns the current value for this system property by delegating to {@link
 * System#getProperty(String)}.
 */
public @Nullable String value() {
 return System.getProperty(key);
}

代码示例来源:origin: google/guava

public void testWriteLinesStream_systemDefaultSeparator() throws IOException {
 String separator = System.getProperty("line.separator");
 sink.writeLines(lines.stream());
 assertContainsExpectedLines(separator);
}

代码示例来源:origin: spring-projects/spring-framework

@BeforeClass
public static void compilerAssumptions() {
  // JiBX compiler is currently not compatible with JDK 9
  Assume.assumeTrue(System.getProperty("java.version").startsWith("1.8."));
}

代码示例来源:origin: spring-projects/spring-framework

@BeforeClass
public static void compilerAssumptions() {
  // JiBX compiler is currently not compatible with JDK 9
  Assume.assumeTrue(System.getProperty("java.version").startsWith("1.8."));
}

代码示例来源:origin: google/guava

public void testWriteLines_stream() throws IOException {
 sink.writeLines(ImmutableList.of("foo", "bar", "baz").stream());
 String separator = System.getProperty("line.separator");
 assertEquals("foo" + separator + "bar" + separator + "baz" + separator, sink.getString());
}

代码示例来源:origin: google/guava

public void testWriteLines_systemDefaultSeparator() throws IOException {
 String separator = System.getProperty("line.separator");
 sink.writeLines(lines);
 assertContainsExpectedLines(separator);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void verifyPropertiesAreAvailableInEnvironment() {
  String userHomeKey = "user.home";
  assertEquals(System.getProperty(userHomeKey), env.getProperty(userHomeKey));
  assertEquals("enigma", env.getProperty("explicit"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@EnabledOnMac
void enabledIfWithSpelOsCheckInCustomComposedAnnotation() {
  String os = System.getProperty("os.name").toLowerCase();
  assertTrue(os.contains("mac"), "This test must be enabled on Mac OS");
  assertFalse(os.contains("win"), "This test must be disabled on Windows");
}

代码示例来源:origin: google/guava

public void testWriteLines_withDefaultSeparator() throws IOException {
 sink.writeLines(ImmutableList.of("foo", "bar", "baz"));
 String separator = System.getProperty("line.separator");
 assertEquals("foo" + separator + "bar" + separator + "baz" + separator, sink.getString());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@DisabledOnMac
void disabledIfWithSpelOsCheckInCustomComposedAnnotation() {
  assertFalse(System.getProperty("os.name").contains("Mac"), "This test must be disabled on Mac OS");
}

代码示例来源:origin: spring-projects/spring-framework

@Parameterized.Parameters(name = "server [{0}]")
public static Object[][] arguments() {
  File base = new File(System.getProperty("java.io.tmpdir"));
  return new Object[][] {
      {new JettyHttpServer()},
      {new ReactorHttpServer()},
      {new TomcatHttpServer(base.getAbsolutePath())},
      {new UndertowHttpServer()}
  };
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPropertyPlaceholderConfigurerWithSystemPropertyFallback() {
  factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class)
      .addPropertyValue("country", "${os.name}").getBeanDefinition());
  PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
  ppc.postProcessBeanFactory(factory);
  TestBean tb = (TestBean) factory.getBean("tb");
  assertEquals(System.getProperty("os.name"), tb.getCountry());
}

代码示例来源:origin: google/guava

public void testGetValue() {
 for (StandardSystemProperty property : StandardSystemProperty.values()) {
  assertEquals(System.getProperty(property.key()), property.value());
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCustomDestroyBean() throws Exception {
  beanFactory.getBean("custom-destroy");
  beanFactory.destroySingletons();
  assertNull(System.getProperty("security.destroy"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testSpringDestroyBean() throws Exception {
  beanFactory.getBean("spring-destroy");
  beanFactory.destroySingletons();
  assertNull(System.getProperty("security.destroy"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testCustomFactoryType() throws Exception {
  assertNull(beanFactory.getType("spring-factory"));
  assertNull(System.getProperty("factory.object.type"));
}

相关文章