input.txt
入力行の各文字が小文字の場合は大文字に、大文字の場合は小文字に変わるように、各行を読み取って各行を印刷しようとしています。さらに、Thread
各行の反転も印刷したいので、これを行うために a を使用したいと思います。
とのエラーが発生しprintUppLow uppLow = new printUppLow();
ますprintRev rev = new printRev();
non-static variable this cannot be referenced from a static context.
コード
public static void main(String args[])
{
String inputfileName="input.txt"; // A file with some text in it
String outputfileName="output.txt"; // File created by this program
String oneLine;
try {
// Open the input file
FileReader fr = new FileReader(inputfileName);
BufferedReader br = new BufferedReader(fr);
// Create the output file
FileWriter fw = new FileWriter(outputfileName);
BufferedWriter bw = new BufferedWriter(fw);
printRev rev = new printRev();
printUppLow uppLow = new printUppLow();
rev.start();
uppLow.start();
// Read the first line
oneLine = br.readLine();
while (oneLine != null) { // Until the line is not empty (will be when you reach End of file)
// Print characters from input file
System.out.println(oneLine);
bw.newLine();
// Read next line
oneLine = br.readLine();
}
// Close the streams
br.close();
bw.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
public class printUppLow extends Thread
{
public void run(String str)
{
String result = "";
for (char c : str.toCharArray())
{
if (Character.isUpperCase(c)){
result += Character.toLowerCase(c); // Convert uppercase to lowercase
}
else{
result += Character.toUpperCase(c); // Convert lowercase to uppercase
}
}
return result; // Return the result
}
}
public class printRev extends Thread
{
public void run()
{
StringBuffer a = new StringBuffer("input.txt");
System.out.println(a.reverse());
}
}