Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1435829
  • 博文数量: 18
  • 博客积分: 9950
  • 博客等级: 中将
  • 技术积分: 4242
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-08 10:08
文章分类

全部博文(18)

文章存档

2009年(3)

2008年(15)

我的朋友

分类: Java

2008-04-28 11:18:25

try{
    //需要生成 .txt的数据文件 
    //FileWriter fw=new FileWriter(Messages.getString("VoteDiaochaAction.3"));

    //建立FileWriter对象,并实例化fw            
    FileWriter fw=null;
    try {

     //column.txt
     fw = new FileWriter   ("../webapps/vote/amcolumn/data/column.txt");
     } catch (RuntimeException e) {
           e.printStackTrace();
     }    
     
     /*
      //Java文件路径问题
       System.out.println(
             Thread.currentThread().getContextClassLoader().getResource(""));
       System.out.println(VoteDiaochaAction.class.getClassLoader().getResource(""));
       System.out.println(ClassLoader.getSystemResource(""));
       System.out.println(VoteDiaochaAction.class.getResource(""));
       System.out.println(VoteDiaochaAction.class.getResource("/"));
       System.out.println(new File("column2.txt").getAbsolutePath());
       System.out.println(System.getProperty("user.dir"));
     */

    
       //FileWriter fw=new FileWriter ("/webRoot/amcolumn/data/column.txt");            

       //将字符串写入文件

       fw.write(data);            
       fw.close();
    } catch (Exception e) {
       e.printStackTrace();
    }

 

Java对文件操作和web的相对路径问题的例子。

Tomcat:在类中输出System.getProperty("user.dir");显示的是%Tomcat_Home%/bin
 
 

获得文件真实路径

string file_real_path=request.getRealPath("mypath/filename");

通常使用request.getRealPath("/");

 

 

相关链接:

http://www.blogjava.net/ericwang/archive/2005/12/16/24301.aspx

阅读(5105) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:tcpdump使用说明

给主人留下些什么吧!~~