So im new to android development and i have been going about everything in a trial and error manner with a lot of searching a long the way. My question is: I have a button that I want to link to a exert of code that will start a download from a particular site. my code is as follows.
public void Download(View Button) {
public void DownloadFromUrl(){
try {
URL url = new URL("www.generic-site.html");
HttpURLConnection c = (HttpURLConnection)
url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String Path = Environment.getExternalStorageDirectory()
+"/download/";
Log.v("PortfolioManger", "PATH: "+Path);
File file = new File(Path);
file.mkdirs();
FileOutputStream fos = new FileOutputStream("site.html");
InputStream is = c.getInputStream();
byte[] buffer = new byte[702];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Log.d("PortfolioManger", "Error: "+e);
}
Log.v("PortfolioManger", "Check: ");
}
What I was attempting to do was use the "public void Download(View Button)" command to launch the download, however im getting the errors:
Multiple markers at this line
- Syntax error, insert "EnumBody" to complete BlockStatements
- Syntax error on token "void", @ expected
- Syntax error, insert "enum Identifier" to complete
EnumHeaderName" error under "Public void DownloadFromUrl()
I know its probably a silly question but can anyone shed some light?