I gotta be honest, it's getting very hard for me to understand the lectures of my professor. I ask questions but I rarely get the answer I'm looking for. This time, he gave us an assignment about FileReaders telling us to search the internet for answers... I've been at this for the past 3 hours and I still couldn't get the answers right.. Please help me.. And please explain my errors so I at least get up to speed with our lectures...
import java.io.*; class HomeWork4 { public static void main (String[] args) throws Exception { BufferedReader brfile = new BufferedReader (new FileReader("Love the Way You Lie.txt")); FileInputStream fis = new FileInputStream("Love the Way You Lie.txt"); BufferedReader brfis = new BufferedReader(new InputStreamReader(fis)); File file = new File ("Love the Way You Lie.txt"); System.out.println("1. ToUpperCase"); //Print the lyrics in uppercase. Does this work? XD System.out.println(file.toUpperCase()); System.out.println("2. The file size is: "+file.length());//get the file size in bytes. System.out.println("3. Getting the second word of the file: ");//get the second word of the file only. I can't seem to get this right.. :( String strLine = null, tmp; while ((tmp = brfis.readLine()) != null) { strLine = tmp; } String lastLine = strLine; System.out.println(lastLine); System.out.println("4. Reverse the text file: ");//Print the lyrics in inverse order. I can't seem to get this working either final StringBuilder stringBuilder = new StringBuilder(file); System.out.println(stringBuilder.reverse()); } }
Any and all help would be appreciated... And any and all explanations would be appreciated more.. XD
Also, my home computer is under repair so I really haven't compiled this with a program. Only with a somewhat unreliable online compiler...
Thanks a lot!