码迷,mamicode.com
首页 > 其他好文 > 详细

如果想要跨平台,在file类下有separtor(),返回锁出平台的文件分隔符

时间:2018-08-05 14:16:36      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:throw   port   color   不同的   平台   pre   try   不同   class   

对于命令:File f2=new file(“d:\\abc\\789\\1.txt”)

这个命令不具备跨平台性,因为不同的OS的文件系统很不相同。

如果想要跨平台,在file类下有separtor(),返回锁出平台的文件分隔符。

File.fdir=new File(File.separator);

String str=”abc”+File.separator+”789”;

使用文件下的方法的时候一定注意是否具备跨平台性。

 

 1 package TomTexts;
 2 import java.io.*;
 3 public class TomTexts_38 {
 4     public static void main(String [] args) 
 5     {
 6     try
 7     {
 8     System.out.println("…正在运行程序…");
 9     throw new IOException("用户自行产生异常");
10     }
11     catch(IOException e)
12     {
13     System.out.println("已捕获了该异常!");
14     }
15     }
16 
17 }

 

如果想要跨平台,在file类下有separtor(),返回锁出平台的文件分隔符

标签:throw   port   color   不同的   平台   pre   try   不同   class   

原文地址:https://www.cnblogs.com/borter/p/9425150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!