If you're using Java 7 you can use the new java.nio.file.attribute package like so:
Path path = FileSystems.getDefault().getPath("/j", "sa");
Files.setAttribute(path, "dos:hidden", true);
Or, if you're using an older version of Java and/or want to do it using Runtime, try this:
Process process = Runtime.getRuntime().exec("cmd.exe /C attrib -s -h -r your_path");
you can use it like this
final String NOMEDIA_FILE = ".nomedia";
path = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "MyAppFolder" );
path.mkdirs();
file= new File(path,NOMEDIA_FILE);
Files.setAttribute(path, "dos:hidden", true);
or
Process process = Runtime.getRuntime().exec("cmd.exe /C attrib -s -h -r"+path);
if (!file.exists())
{
try
{
file.createNewFile();
Log.e("NOMEDIA_FILE"," ");
}
catch (IOException e)
{
e.printStackTrace();
}
}