reformatting java code problem
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 :
Code Java:
public class Test
{
public static void main(String[] args)
{
// some statements
}
}
would be reformatted to :
Code Java:
public class Test{
public static void main(String[] args){
// some statements
}
}
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.
Code Java:
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..
}
}
}
}
}