所以即時通訊新的android開發和我一直在嘗試和錯誤的方式進行了大量的搜索很長的一切。我的問題是:我有一個按鈕,我想鏈接到一段代碼,它將從一個特定的站點開始下載。我的代碼如下。點擊按鈕文件下載?
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: ");
}
我試圖做的是使用「公共無效下載(查看按鈕)」命令來啓動下載,但即時得到錯誤:
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()
我知道它可能是一個愚蠢的問題,但任何人都可以點亮一下嗎?
如何我可以修復它任何提示? – luke
通過學習Java之前學習Android – mibollma