Java, automatically change file name if file exists
If you want to save a file to a certain directory, but don’t want to overwrite existing file. You want to append the file name with an index. Say, you want your file as “myFile.txt”. If “myFile.txt” exists already, you want to change your file name to “myFile1.txt”.
Here is the solution.
String fileName = "myFile";
String extension = ".txt";
String fixedPrefix = fileName;
Integer i=1;
boolean oldFileExist = true;
while (oldFileExist)
{
try {
FileInputStream inputStream = new FileInputStream(fileName + extension);
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName = fixedPrefix + i.toString();
i++;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
oldFileExist = false;
}
}
fileName = fileName + extenstion; //fileName now should be like myFile1.txt
//now continue to create a file with fileName as name, then write to it as normal
BufferedWriter fileBuff = new BufferedWriter(new FileWriter(fileName , false));
//write your content here
//bla bla
//.....
fileBuff.close()
awesome SVN branching in Eclipse
Exactly what official eclipse manual is missing
http://www.saltycrane.com/blog/2007/03/how-to-setup-subclipse-project-to/
ideas Mar 07
07/03:
State:
- Green, car start moving, leading part of the queue with speed significantly > 0, trailing part still 0
- Green, cars well into moving stage, no cars with speed = 0, we can reach this stage without previous green stage (new oncoming cars hit green light timely)
- Green, but green is about to expire soon, and cars going to make stops (the closest cars will hit the red light)
- Red, new red, with a bunch of cars coming (cars still moving, and making stops soon)
- Red, well into red, with leading part queuing, later part still moving
- Red, all cars stopped.
- Red, but red going to expire, some coming cars don’t have to stop.
Some thoughts: to capture case 1 and 2, just use car features (with corresponding weight components of weight vector): moving queue, still queue. Again, to capture cases 4, 5, 6, just need moving queue and still queue.
Case 3, case 7: do I need more feature for it?
password-less ssh login
- On local machine, generate key pairs by
ssh-keygen
follow the prompt, enter nothing as password, a pair of key files (id_rsa, id_rsa.pub) is generated in folder .ssh
- Copy the file .ssh/id_rsa.pub to the .ssh folder as new name “authourized_keys” via scp, command as below:
scp .ssh/id_rsa.pub user@host.com:~/.ssh/authorized_keys
That’s it!
How to use 3G Internet in Vietnam
Hey,
From my travel experience, Internet is really saving awkward foreign travellers bunch of hassle. So, here come the time-saving tips on how to use Internet on your smart phones (iPhone, Blackberry, any phone that have 3G function works).
Step 1:
Once you arrive in Vietnam, find any phone-card shop (wherever you see a sign listing all kinds of carriers’ names, must be it). Ask for Vinaphone SIM pack. The credit you get on the first charging is always at least double, sometimes triple the amount you pay. Depending on your stay, pick suitable kit. As of July 2010, for a week, I suggest the 180,000VND (which get you 360,000 VND credit). More on SIM pack tip later, at the footnote.
Step 2:
Compose a message with content “GPRS ON” (without the quote), send to 333 or 888.
Step 3:
Compose a message to send to 888, with content as listed down here, according to your usage
| SMS content | Price | Bandwidth |
| M10 ON | 10,000 VND/30 days | 10 Mb |
| M25 ON | 25,000 VND/30 days | 35 Mb |
| M50 ON | 50,000 VND/30 days | 100 Mb |
| U1 ON | 12,000 VND/days | unlimited |
| U7 ON | 80,000 VND/days | unlimited |
| U30 ON | 300,000 VND/30 days | unlimited |
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!