Install Autoit and try the following.
How to install autoit, You can install using this link.
Once you installed.Then do the following things:
Start menu -> All Programs -> AutoIt V3 -> SciTE Script Editor

Copy this and paste there : This is for fire fox
ControlFocus("File Upload","","Edit")
Sleep(2000)
send("test.txt")
Sleep(2000)
send("{ENTER}")

Compile it :
Tools -> Compile or Cntr+F7
Create .exe file from .au3 file:
Start -> All Program -> AutoIt v3 -> Compile Script to .exe

Once you run this .exe file will be created under the folder where .au3 file is located.You need to refer this file in you test code.
My html file
<html>
<body>
<script>
function uploadOnChange(e) {
var filename = e.value;var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex +1);
}
document.getElementById('filename').value = filename;
}
</script>
<input id="upload" type="file" onChange="uploadOnChange(this)" />
<input id="filename" type="text" />
</body>
</html>
My Test code :
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class FileUploadTest {
private static WebDriver driver = null;
@Test
public void testFileUpload() throws IOException, InterruptedException, IOException {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("file:///C:/Users/sv/Desktop/uploadDoc.html");
driver.findElement(By.id("upload")).click();
Runtime.getRuntime().exec("<exe file path>");
Thread.sleep(6000);
System.out.println(driver.findElement(By.id("filename")).getText());
driver.close();
}
}
For more info, Please refer this link