I am trying to remove whitespaces in the beginning of my String by doing the .trim()
method. But when I try to calculate how many whitespaces I remove it won't work. I have tried making an equation:
int spaces = line.length() - line.trim().length()
. But for some reason it always ends up saying the length of the line thats being inputted. Am I missing something here? Or is it some other part of my code?
public Squeeze(FileInput inFile, FileOutput outFile)
{
int spaces = 0;
String line = "";
while(inFile.hasMoreLines())
{
line = inFile.readLine();
line = line.trim();
spaces = line.length() - line.trim().length();
outFile.println(spaces + line);
}
outFile.close();
}