Text Analyzer - Properly implementing Java coding style
Single responsibility principle

The main method does most of the job.
It would be better to split that up to smaller methods,
in a way that each method has a single responsibility.
You will end up with something more modular, reusable, testable.

Make variables local when possible

stringBuffer is only used within the main method,
so doesn't need to be a member variable.
Declare it right before you need it,
in fact, it's best at the time of initialization:

StringBuffer stringBuffer = new StringBuffer();


Avoid static variables when possible

None of the static variables were needed.
In general, avoid static variables as much as possible,
especially if they are mutable.

wordCount is not as simple to eliminate as stringBuffer,
but still easy enough:
make getWordsCount return a Map&lt;String, Integer&gt;.

Use the enhanced for-each loop

Instead of this:


for (int i = 0;  i &lt; l.size(); i++) {
    s2 = s2 + l.get(i) + "\n";
}



Since you don't need the index values and it's just clutter,
the recommended writing style is this:

for (String word : l) {
    s2 = s2 + word + "\n";
}


This has another advantage that in this form the loop can work efficiently not only with an ArrayList, but with a LinkedList too,
because elements are no longer accessed by index.

Use boolean expressions directly

Instead of this:


    while (scanner.hasNext() == true) {



You can and should write this:

    while (scanner.hasNext()) {


Refer to types by interfaces

Instead of this:


private static HashMap&lt;String, Integer&gt; wordCount = new HashMap&lt;String, Integer&gt;();



This would be better:

private static Map&lt;String, Integer&gt; wordCount = new HashMap&lt;String, Integer&gt;();


Use Java 7

I'm guessing you're using an older version because of things like this:


List&lt;String&gt; l = new ArrayList&lt;String&gt;(s);



Starting from Java 7 you don't need to specify the type parameters at the right hand side of expressions, the compiler can figure them out most of the time, and you can use the diamond operator &lt;&gt; like this:

List&lt;String&gt; l = new ArrayList&lt;&gt;(s);


Unused imports

You have some unused imports:


import java.io.FileNotFoundException;
import java.util.Map;



I'm surprised your IDE doesn't warn about them.
In fact it probably does.
Strive to keep warnings to minimum, ideally down to zero.

Extremely poor names

In this code,
the variable names s, l, s2 are bordering obfuscation.


Set&lt;String&gt; s = wordCount.keySet();
List&lt;String&gt; l = new ArrayList&lt;&gt;(s);
Collections.sort(l);
String s2 = "";
for (int i = 0;  i &lt; l.size(); i++) {
    s2 = s2 + l.get(i) + "\n";
}



Sure you can come up with better names for these,
which will make the code so much more readable.

Prefer StringBuilder over StringBuffer

StringBuffer synchronizes internally to make it thread safe.
This is rarely needed in practice,
and in this example it's completely unnecessary.
Use StringBuilder instead.

Btw, is there a benefit to accumulating the output in memory before producing the output? Probably not.
You could just write the output directly,
without building up a long string.

Put braces consistently

In this code, you put braces for the if, but not for the else


if (tokenCount == null) {
    wordCount.put(token, 1);
} else
    wordCount.put(token, tokenCount + 1);



At the minimum, be consistent.
The recommendation is to put braces always.