try {
BufferedReader in = new BufferedReader(new FileReader("C:/temp/temp.txt"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
} catch (IOException e) {
}
Saturday, June 27, 2009
How to Read Text from Standard Input
11:26 PM
Posted by
Techsavy
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = "";
while (str != null) {
str = in.readLine();
System.out.println(str);
}
} catch (IOException e) {
}
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = "";
while (str != null) {
str = in.readLine();
System.out.println(str);
}
} catch (IOException e) {
}
How to Delete a Directory
11:24 PM
Posted by
Techsavy
boolean success = (new File("directoryName")).delete();
if (success) {
// Deletion successful
}
if (success) {
// Deletion successful
}
How to Get the Current Working Directory
11:23 PM
Posted by
Techsavy
String currrentDirectory = System.getProperty("user.dir");
How to Rename a File
6:48 PM
Posted by
Techsavy
File oldFile = new File("C:/temp/oldTemp.txt");
File newFile = new File("C:/temp/newTemp.txt");
// Rename file
boolean success = oldFile.renameTo(newFile);
if (success) {
// File was successfully renamed
}
File newFile = new File("C:/temp/newTemp.txt");
// Rename file
boolean success = oldFile.renameTo(newFile);
if (success) {
// File was successfully renamed
}
How Delete a File
6:45 PM
Posted by
Techsavy
boolean success = (new File("C:/temp/temp.txt")).delete();
if (success) {
// Deletion succeeded
}
if (success) {
// Deletion succeeded
}
How to Get the Size of a File
6:42 PM
Posted by
Techsavy
File file = new File("C:/temp/temp.txt");
// Get the number of bytes in the file
long length = file.length();
// Get the number of bytes in the file
long length = file.length();
Subscribe to:
Posts (Atom)