-1

So I'm writing some html code where someone can browse a file and save it(using some java code) in a different location under a new name. I've attempted a couple of different ways of doing this by browsing a file then reading and writing the file. However, each time I try to execute the code, it says my function has not been defined. Below is sample code, where I browse a file and then want to save the file to a new location.

The csv file would have 3 columns and 3000+ rows.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
 <title>Java</title>

 <script>
 import java.io.File;

     function ReadWriteCSVFile() {
         File myFile = document.getElementById('fileinput').files;
         myFile.renameTo(new File("/Directory/location/Data.csv"));
     }

</script> 
</head>

<body>

<form>

 Select a file: <input type="file" name="img" id="fileinput">
   <input type="button" id="addButton" value="Add to CSV File" onClick="ReadWriteCSVFile()" />

</form>

</body>
</html>

I can not seem to figure out why it cannot read my function for the onClick or which method would be best. Thank you for your assistance.

Lcat91
  • 804
  • 3
  • 10
  • 14
  • `function` is not a keyword in Java. Did you intend to write Java *code* or JavaSCRIPT? – Rainbolt Mar 04 '14 at 17:30
  • Oh, ok. I intended to write a javascript. So would I have to to define my script section in a different way? – Lcat91 Mar 04 '14 at 17:44
  • Well, the code inside of your Script tags is a mix of Java and Javascript. You declared your function with the `function` keyword, which is Javascript. All of the remainder of the code is in Java. Perhaps if you added ` – Rainbolt Mar 04 '14 at 17:46

1 Answers1

0

You're mixing Java and JavaScript, which does not work. Java the compiled language is not JavaScript. You cannot call a Java Method like that. To accomplish what you're trying to do, you will need to create a Java Applet.

Java Applets

Eddie
  • 466
  • 5
  • 8