问题描述
所以,即时通讯新Android开发,我已持续约了很多搜索很长的路的一切都在一个试错的方式。我的问题是:我有一个按钮,我想链接到code的使出,将开始从一个特定的网站下载。我的code是如下:
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?
推荐答案
您不能将一个函数另一个函数里面
You can't place one function inside another function
public void Download(View Button) {
public void DownloadFromUrl(){
这篇关于按钮文件下载点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!