zoukankan      html  css  js  c++  java
  • 系统变量中设定文件路径

    这是一个小例子,经过测试过的。

    package com.surekam.mpm.casemanagement.web.test;

    import java.io.File;

    import java.io.FileNotFoundException;

    import java.io.FileOutputStream;

    import java.io.IOException;

    import java.io.OutputStream;

    public class PropertyTest {

    public static void main(String[] args) throws IOException {

    System.setProperty("java.io.tmpdir", "d:\\test\\test");

    System.out.println(System.getProperty("java.io.tmpdir"));

    String filePath = System.getProperty("java.io.tmpdir");

    File file = new File(filePath);

    System.out.println(file.exists());

    if(!file.exists()){

    file.mkdirs();

    }

    file = null;

    file = new File(filePath+"\\test.txt");

    System.out.println(file.toURI().toASCIIString()+"  "+file.toURL().toString());

    try {

    OutputStream output = new FileOutputStream(file);

    output.write("我是一个中国人。".getBytes());

    output.flush();

    output.close();

    } catch (FileNotFoundException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    } catch (IOException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    }

  • 相关阅读:
    Python设计模式
    Python设计模式
    Python设计模式
    Python设计模式
    Python设计模式
    Python设计模式
    Python设计模式
    Python设计模式
    composer安装以及更新问题,配置中国镜像源。
    PHP使用文件排它锁,应对小型并发
  • 原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100481.html
Copyright © 2011-2022 走看看