I think you're missing a quote (') here...
Code:

SHELL '%COMSPEC% /e:1024 /c "dir /b /ad /o-n %ProgramFiles%\Java\ >> c:\JavaDirectory.txt"