on 07-30-2009 8:46 AM
Hi Experts,
Java, we have a requirement where we need to rename particular file with the string which is inside the file.
String should be inside the file between 42 and 59 characters.
Greatly appreciated if you help .........
Thanks,
Venkat
Hi,
You can try the following code....
File oldFile = new File("C:/check/Edit1.txt");
String fileName = "";
try{
FileReader fr = new FileReader("C:/check/Edit1.txt");
char ch;
int count=1;
do {
ch = (char)fr.read();
count++;
if (ch != -1 && count >= 42)
fileName = fileName.concat(Character.toString(ch));
} while (ch != -1 && count<=59);
System.out.println(fileName);
fr.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
oldFile.renameTo(new File("C:/check/"fileName".txt"));
If you get any issues let me know.........
Regards,
Lakshmi Prasad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.