Java常用代码
/**
* 创建一个新的文件
* @param relativePath 相对路径
* @param fileName 文件名
* @return
* @throws IOException
*/
public File createFile(String relativePath, String fileName) throws IOException {
String upPath = getFileUploadPath() + relativePath + "\\";
System.out.println("upPath:" + upPath);/////////////////////////////
System.out.println("fileName:" + fileName);/////////////////////////////
String nameWithoutExt = getNameWithoutExtension(fileName);
String ext = getExtension(fileName);
createDirectory(upPath);// 上传目录不存在则创建目录
File newFile = new File(upPath + fileName);
// 若有重名文件则修改名称创建新的文件
for (int counter = 1; newFile.exists(); counter ++) {
fileName = nameWithoutExt + "(" + String.valueOf(counter) + ")." + ext;
newFile = new File(upPath + fileName);
}
newFile.createNewFile();
return newFile;
}
=================================================================================
/**
* 文件的写入 (单行写入)
* @param filePath(文件路径)
* @param fileName(文件名)
* @param args
* @throws IOException
*/
public void writeF
相关文档:
1、利用System.getProperty()函数获取当前路径:
System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径
2、使用File提供的函数获取当前路径:
File directory = new File("");//设定为当前文件夹
try{
System.out.println(directory.getCanonicalPa ......
一. 什么是Native Method
简单地讲,一个Native Method就是一个java调用非java代码的接口。一个Native Method是这样一个java的方法:该方法的实现由非java语言实现,比如C。这个特征并非java所特有,很多其它的编程语言都有这一机制,比如在C++中,你可以用extern "C"告知C++编译器去调用一个C的函 ......
Java关键字(keywords)
abstract default if private this
boolean do implements &nbs ......
到http://download.csdn.net/source/1781433下载jxl.jar文件
/*Title是保存出来的文件名,gbl_LastOpenPath用于记录上次打开的路径*/
public void ExportToExcel(JTable table, String Title){
File DefaultFile;
JFileChooser fc = new JFileChooser();
File file;
if(gbl_LastOpen ......
String和StringBuffer的区别,网上资料可以说是数不胜数,但是看到这篇文章,感觉里面做的小例子很有代表性,所以转一下,并自己做了一点总结。
在java中有3个类来负责字符的操作。
1.Character 是进行单个字符操作的,
2.String 对一串字符进行操作。不可变类。
3.StringBuffer 也是对一串字符进行操作,但是可 ......