I am writing a program that will change java code. It changes the next-line bracket system into the end-of-line bracket system. I am using String to do this. Here is my code:
public static void main(String[] args) throws Exception
{
File file = new File("test.text");
//PrintWriter output = new PrintWriter(file);
Scanner input = new Scanner(file);
System.out.println("Does it exist? " + file.exists());
while(input.hasNext())
{
String first = input.next();
String second = input.next();
if (first == "{")
{
second = first.replace("{", "\n{");
System.out.println(second);
}
else
{
System.out.println(first);
}
}
}
My test.txt looks like:
"hello{ how are you{"
So far it just takes out the word before the bracket. I am trying to get it to put the bracket on a new line.
String.equals(), not==. And you don't want to check for"{"anyway, you want to check for a"{"with nothing before it except whitespace. If it's not just for fun, use Jalopy/etc.first/second(I think at this stage they're confusing more than they're helping).