java_aat_6
java_aat_6
// Setting priorities
thread1.setPriority(Thread.MIN_PRIORITY); // Low priority
thread2.setPriority(Thread.NORM_PRIORITY); // Normal priority
thread3.setPriority(Thread.MAX_PRIORITY); // High priority
// Starting threads
thread1.start();
thread2.start();
thread3.start();
}
}
OutPut:
2.Write a Java program to check whether the fi le is readable, writable and hidden.
import java.io.File;
if (file.exists()) {
// Check if the file is readable
if (file.canRead()) {
System.out.println("The file is readable.");
} else {
System.out.println("The file is not readable.");
}
if (file.canWrite()) {
System.out.println("The file is writable.");
} else {
System.out.println("The file is not writable.");
}
if (file.isHidden()) {
System.out.println("The file is hidden.");
} else {
System.out.println("The file is not hidden.");
}
} else {
System.out.println("The file does not exist.");
}
}
}
OutPut:
3.Write a program that will count the number of characters and words in a file.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
int wordCount = 0;
int characterCount = 0;
characterCount += line.length();
wordCount += words.length;
}
} catch (IOException e) {
System.out.println("An error occurred while reading the file: " + e.getMessage());
}