- 浏览: 121041 次
- 性别:
- 来自: 陕西
文章分类
- 全部博客 (90)
- ASP中错误代码解析 (1)
- Javase (32)
- JavaEE (0)
- Hibernate (10)
- Spring (2)
- Struts (1)
- Oracle (3)
- ASP (2)
- JDBC (0)
- JavaEE+Hibernate+Spring+Struts (1)
- MySql (0)
- SQL (6)
- servlet (0)
- JavaScript (4)
- 软件测试 (0)
- 架构分析 (0)
- 面试 (1)
- Flash (0)
- PhotoShop (0)
- 文章 (2)
- Ajax (1)
- JSP (8)
- C# (1)
- PHP (2)
- ASP.NET (0)
- Dreamwerver (0)
- Linux (0)
- 经验技巧 (5)
- C++ (0)
- 每日一个问题总结 (4)
最新评论
-
bb12152205gg:
jsp与servlet的区别
简单 ...
JSP登录验证功能的实现 -
GoodDemo:
JSP登录验证功能的实现 -
leelj:
看看 这里:http://www.iteye.com/topi ...
JAVA每日一题01 -
lpp333:
华为的兄弟吧~~!!
JAVA每日一题01 -
Hooopo:
night_stalker 写道shuffle 犯规呀~~
不 ...
JAVA每日一题01
题目:在很多操作系统中,文件名长度都有限制,所以在文件名后面添加_old有时可能会失败。修改避免覆盖文件的程序实例,将一个三位数添加到文件名的末尾,以此来和已存在的文件向区别,而不仅仅是添加_old。程序应该检查存在文件的文件名后面的三位数,并用一定数量的增加值将其替换,以使其具有唯一性。(也就是说,将最后三位数增加1,直到产生了具有唯一性的文件名为止。)
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
public class AvoidOverwritingFile {
public static void main(String[] args) {
String filepath = "C:/Beg Java Stuff/myFile.txt";
if(args.length>0) {
filepath = args[0];
}
File aFile = new File(filepath);
FileOutputStream outputFile = null; // Stores the stream reference
if (aFile.isFile()) {
File newFile = aFile; // Start with the original file
// We will append three digits to the file to make it unique
do {
String name = newFile.getName(); // Get the name of the file
int period = name.indexOf('.'); // Find the separator for the extension
if(period == -1) {
newFile = new File(newFile.getParent(), extendName(name)); // ***
} else {
newFile = new File(newFile.getParent(),
extendName(name.substring(0, period))
+ name.substring(period));
}
} while(!aFile.renameTo(newFile)); // Stop when renaming works
}
// Now we can create the new file
try {
// Create the stream opened to append data
outputFile = new FileOutputStream(aFile);
System.out.println(aFile.getName()+" output stream created");
} catch (FileNotFoundException e) {
e.printStackTrace(System.err);
}
System.exit(0);
}
// *** new method to adding or increment three digits at the end of a name starting at "000"
private static String extendName(String name) {
StringBuffer newName = new StringBuffer(name); // We will create the new name in this buffer
String digits = newName.substring(newName.length()-3,newName.length()); // Get last three characters
int number = 0;
try {
number = Integer.parseInt(digits); // Parse the last 3 characters
++number; // We got an integer so increment it
newName.delete(newName.length()-3,newName.length());
} catch(NumberFormatException nfe) { // Last 3 characters not an integer
// This will be thrown if digits is not a parsable integer
// but if we just do nothing here execution will continue
// with number as its initial value, which is zero.
}
digits = String.valueOf(number); // Get number as a string
assert digits.length() < 4; // Make sure we don't run over three digits!
// We can now create the new name by appending "000" and replacing some or all of these
// by the digits in the String, digits.
return newName.append("000").replace(newName.length()-digits.length(),newName.length(), digits).toString();
}
}
发表评论
-
JAVA每日一题25
2009-05-06 17:57 1024这段时间太忙了,咋们继续。题目:修改避免覆盖文件的程 ... -
JAVA每日一题24
2009-04-20 15:59 1194最近比较忙,没有很好的做,不好意思各位。 ... -
JAVA每日一题23
2009-04-11 17:34 1035题目:这是一道C语言题,809*??=800*??+9 ... -
JAVA每日一题22
2009-04-09 18:51 1051题目:有两各线程accountant和cashier ... -
JAVA每日一题21
2009-04-08 18:16 1007题目: 在一个文本框中输入网址,然后点击确定按钮读取服 ... -
JAVA每日一题20
2009-04-07 16:46 1042题目: 简单做一个B/S结构的商业应用——购物车。JS ... -
JAVA每日一题19
2009-04-06 17:32 1485题目:编写一个不同界面的风格的显示。 import ... -
JAVA每日一题17
2009-04-03 07:25 1693题目:使用JAVA编写扫描网站信的代码,呵呵! imp ... -
JAVA每日一题16
2009-04-02 16:51 1254题目:用JAVA做一个控制访问权限的例子。 ... -
JAVA每日一题15
2009-03-31 07:32 1925题目:用JAVA编写扫描网站信息的代码(流的使用和网络的 ... -
JAVA每日一题14
2009-03-30 19:30 1160题目:用JAVA编写一个压缩文件的例子。 packa ... -
JAVA每日一题12
2009-03-25 07:24 1450题目:做一个简单的收发电子邮件的代码。还需各位指教! ... -
JAVA每日一题11
2009-03-23 13:20 987题目:使用进度条的一个例子。图片自己找一个几个啊! ... -
JAVA每日一题10
2009-03-22 14:03 1054题目:用JAVA做一个数字签名的例子。 packa ... -
JAVA每日一题09
2009-03-21 07:40 944题目:今天实现C/S多线程的一个简单例子。 / ... -
JAVA每日一题08
2009-03-20 07:31 1047今天的题目更有意思啊!好多人会感兴趣的。呵呵! 题目 ... -
JAVA每日一题06
2009-03-18 07:24 2707这个题目感觉有意思,大家分享一下哦. 题目:编写程序利用 ... -
JAVA每日一题05
2009-03-17 07:58 1073题目:定义接口OneToN,在接口中定义方法jisuan(in ... -
Java小技巧:关于Cookie的操作
2009-03-16 14:04 1383测试环境:JDK1.5、Tomcat5.5 1.设置Co ... -
JAVA每日一题04
2009-03-16 10:47 960一个C语言题:题目:用指向指针的指针的方法对n个整数排序并输出 ...
相关推荐
Java每日一题20160906,每日一道Java编程题,提高自己
NULL 博文链接:https://duyiwuer.iteye.com/blog/362849
NULL 博文链接:https://duyiwuer.iteye.com/blog/353541
NULL 博文链接:https://jythoner.iteye.com/blog/344407
java每日一练练习题
Java方向每日一题day18_11月25日编程题答案1
NULL 博文链接:https://duyiwuer.iteye.com/blog/351913
Java方向每日一题day17_11月24日编程题答案1
java面试题,参考面试使用,与什么不懂的不用联系我,我随便传的东西,不传不让下载,真烦
9. 以下关于java封装的描述中,正确的是: 1. 标题:DNA序列 | 时间限制:1秒 | 内存限制:32768K 2. 标题:百万富翁问题 | 时间限制:
比特科技制作[编程题]44581-寻找第K大链接:https://www.nowcoder.com/questionTerminal/e016ad9b7f0b4
1. 执行如下程序,输出结果是( ) 3. 下列选项中属于面向对象设计方法主要特征的是( ) 6. 在基本 JAVA 类型中,如果不明确指定,整数型的默认是 _
整理互联网常见面试题,为春招、校招和社招做准备。如若不能下载,关注公众号“每日技术分享”,可免费下载资源。
干货资源推荐: JVM干货调试视频教程分享 50份优秀Java求职者简历 SpringCloud前后端分离实战项目...本资源整理自互联网,仅供学习交流使用,请勿商用,坚持每日分享一套Java学习资源干货,一起提高,一起进步!!!
leetcode-java:每日一题leetcode-java版
1. 以下哪项是类实例化的语句 6. 变量a是一个64位有符号的整数,初始值用16进制表示为:0Xf000000000000000 7. HashSet子类依靠
一些考试的java习题,一些试卷,考生可能用处大点
leetcode 答案 leetcode-java 每日更新一题,Java编写的LeetCode算法题目答案。
Leetcode每日LeetCode每日一题Java实现
推出了每日一题活动。借此打卡! ID Difficulty Solution Series Finish Time Java C C++ Address 1 ☆ 2019-02-29 ✓ 225 ☆ 每日一题 2020-03-01 ✓ 206 ☆ 每日一题 2020-03-02 ✓ 面试题 ☆ 每日一题 2020-03-03...