hello, i would really apreciate any help on this one.. i have just started file i/o in java and already the homework is bugging me.
I am to write a program that reformats java source code from the next-line brace style to the end-of-line brace style. for example the following code :
public class Test { public static void main(String[] args) { // some statements } }
would be reformatted to :
my attempted code so far is below.. i don't know if i can use concat() in this instance and if i am even doing anything right... please help.. thanks.public class Test{ public static void main(String[] args){ // some statements } }
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { File file = new File("C:\\JackTest\\test.txt"); format(file); } public static void format(File f) throws Exception { Scanner input = new Scanner(f); String[] lines = new String[7]; while (input.hasNext()) { for (int i = 0; i < 7; i++) { lines[i] = input.nextLine(); if (lines[i].startsWith("{")) { lines[i-1].concat("{"); // i am stuck here.. } } } } }