- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 javame 项目,我正在尝试创建一种方法来下载 mp3 文件并将其保存到手机。该方法如下所示,不幸的是它一直抛出java.lang.illegalargument异常。
public void Download_KeyTest()
{
FileConnection file = null;
OutputStream outStream = null;
String resumeJSON = mPreferences.get("resume");
JSONObject resumeObject;
try {
resumeObject = new JSONObject(resumeJSON);
String key=resumeObject.get("code").toString();
String inputStr=getTextField12().getString();
if (inputStr.equals(key))
{
Enumeration roots = FileSystemRegistry.listRoots();
String currentRoot = null;
while (roots.hasMoreElements()) {
currentRoot = (String) roots.nextElement();
System.out.println(currentRoot);
}
HttpConnection hc = null;
DataInputStream in = null;
try {
String url = d_url+resumeObject.getJSONObject("sObject").get("loc").toString();
String sname = urlEncode(resumeObject.getJSONObject("sObject").getString("name").toString());
hc = (HttpConnection)Connector.open(url);
int length = (int)hc.getLength();
byte[] data = null;
if (length != -1) {
switchDisplayable(null,getWaitScreen1());
data = new byte[length];
in = new DataInputStream(hc.openInputStream());
in.readFully(data);
}
else {
// If content length is not given, read in chunks.
switchDisplayable(null,getWaitScreen1());
int chunkSize = 512;
int index = 0;
int readLength = 0;
in = new DataInputStream(hc.openInputStream());
data = new byte[chunkSize];
do {
if (data.length < index + chunkSize) {
byte[] newData = new byte[index + chunkSize];
System.arraycopy(data, 0, newData, 0, data.length);
data = newData;
}
readLength = in.read(data, index, chunkSize);
index += readLength;
} while (readLength == chunkSize);
length = index;
}
getWaitScreen1().setText("Download Complete");
try {
// Get path to photos folder.
String dirMusic = System.getProperty("fileconn.dir.memorycard.music");
if(dirMusic == null) {
dirMusic=currentRoot;
//throw new Exception("Unable get music folder name");
}
String fileName = dirMusic + sname +".mp3";
// Open file
file = (FileConnection)Connector.open(fileName,
Connector.READ_WRITE);
// If there is no file then create it
if(file.exists() == false) {
file.create();
}
// Write data received from camera while making snapshot to file
outStream = file.openOutputStream();
outStream.write(data);
System.out.println(file.availableSize());
//file.setHidden(false);
getWaitScreen1().setText("Song saved to music folder.");
} catch(IOException ioe) {
Alert alertx = new Alert("IO error", ioe.toString(), null, AlertType.ERROR);
alertx.setTimeout(Alert.FOREVER);
switchDisplayable(alertx,getDownloadVerifyKeyForm());
} catch(Exception exc) {
Alert alertx = new Alert("Error", exc.toString()+exc.getMessage(), null, AlertType.ERROR);
exc.printStackTrace();
alertx.setTimeout(Alert.FOREVER);
switchDisplayable(alertx,getDownloadVerifyKeyForm());
} finally {
// Try to close file
try {
if(outStream != null) {
outStream.close();
}
if(file != null) {
file.close();
}
} catch(Exception exc) {
// Do nothing
exc.printStackTrace();
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
} catch (Exception ex)
{
ex.printStackTrace();
}
}
这是我得到的错误
java.lang.IllegalArgumentException
at javax.microedition.io.Connector.getProtocolInstance(), bci=28
at javax.microedition.io.Connector.open(), bci=24
at javax.microedition.io.Connector.open(), bci=3
- spinapp.SpinApp.Download_KeyTest(SpinApp.java:703)
代码中的第703行是这样的
hc = (HttpConnection)Connector.open(url);
最佳答案
如果 URL 无效,
Connector.open(String)
将抛出 IllegalArgumentException
,因此我们真正需要查看的是准确 URL你正在传入。
由于 Stack Overflow 评论格式的工作方式,很难判断具体是哪个 URL。为了便于将来引用,如果您想将准确的 URL 粘贴到评论中,请将其格式设置为代码,并在其周围添加单刻度线。因此,判断您的 url
变量是否包含 protocol 前缀有点困难。
但是,您的完整 URL 可能应该是
http://127.0.0.1/relief/api/uploads/p17gnmso5duql0lnhevja15td5.mp3
显然,在测试 URL 时,将 URL 粘贴到桌面浏览器中通常也是一个好主意,并确保它也能在桌面浏览器中正常工作。此 URL (host=127.0.0.1) 表示您正在与模拟器相同的计算机上运行服务器。
(这提出了另一点......您说这是针对您问题中的电话,但 127.0.0.1 服务器地址仅在您运行时才有效在模拟器中)
<小时/>编辑:再次查看您的评论后,我想知道该行是否没有发生异常:
file = (FileConnection)Connector.open(fileName,
Connector.READ_WRITE);
如果fileName
等于root1/bogolako.mp3
,那么您缺少该调用的协议(protocol)。您应该在 fileName
前面加上 "file:///"
,假设 "/root1/"
实际上是模拟器上有效的绝对路径.
关于javame - 下载并保存 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910766/
当我尝试通过我的 .exe 文件从 url 下载 .pdf 文件时出现以下错误。 The server committed a protocol violation. Section=Response
我是一家非营利组织的 G Suite 管理员,刚刚发现数据导出功能,这似乎是个人帐户的外卖。 导出文件已准备好,现在可以从 Google Cloud Platform Storage 中的存储桶下载。
导航 引言 总体思路 七牛云相关的配置文件 获取七牛云上传token 相关类定义 核心代码实现 获取七牛云图片下载链接 公开空
这不是后端编程问题。我只能修改标记或脚本(或文档本身)。我在这里问的原因是因为我对适当术语的所有搜索都不可避免地导致有关编程此功能的问题和解决方案。我不是试图通过编程来强制它;我必须找出此 PDF 行
您好,我已在 Google AdSense 中注册,我想使用适用于 iOS 的 SDK,但目前我找不到 SDK 下载链接。 我的申请已获批准。 任何人都知道如何下载这个sdk。 我使用这个链接来描述如
我需要为当前在 SourceForge 上的 github 项目提供二进制文件和文档。在那里,我可以为我需要的下载提供一个目录结构,因为我必须为大约 10 个不同的操作系统提供几个版本。 github
我从 Canvas 下载绘图时遇到问题。这是我的代码: function downloadCanvas(link, canvasId, filename) { link.href =
ASP.NET 项目 我将使用 Azure 进行存储。问题(要求): 在我的项目中,我让注册用户下载文件。但我不希望用户将此下载链接分享给未注册的人(例如:我给注册用户的下载链接只能在他们的计算机上下
我编写了一个servlet,用于检查http header ,但我不知道为什么当页面加载时,它会自动开始下载。 /* * To change this template, choose To
我正在尝试将下载添加到我的网络浏览器,但遇到的问题是获取您尝试下载的文件的名称。这是我的下载代码: engine.locationProperty().addListener(new ChangeLi
我正在尝试下载网站的 html: String encoding = "UTF-8"; HttpContext localContext = new BasicHttpContext();
我制作了一个带有“开始下载”按钮的框架,用于从网站下载 JAR。 问题是每当我点击开始下载按钮时,整个框架就会卡住,直到下载完成,然后就正常了。 我该如何解决这个问题? 这是单击按钮时执行的代码 p
我得到这段代码来实现一些东西,它可以帮助我从给定的 URL 下载文件。 -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSes
我正在尝试创建一个 Controller 来使用流方法下载和上传文件,在我的例子中,所有文件都作为 Blob 保存在数据库中。我阅读了 Jboss Netty 的文档,但我认为这不是我的最佳解决方案。
下载并保存文件 let destination: DownloadRequest.DownloadFileDestination = { _, _ in // var fileURL = sel
使用 htaccess 我基本上试图禁止访问该页面,即 http://example.com , 但它仍然允许人们下载文件,如果他们有直接链接即 http://example.com/hi.zip .
我正在寻求将脚本与我的控制面板集成,并且由于我是新手脚本编写者而遇到问题。我想做的是用 1 个脚本下载一个文件并解压它。 示例: wget http://example.com/example.tar
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
这个问题在这里已经有了答案: Top techniques to avoid 'data scraping' from a website database (14 个答案) 关闭 5 年前。 我有
这个问题在这里已经有了答案: Reading and parsing email from Gmail using C#, C++ or Python (6 个答案) 关闭 7 年前。 我只是想,是
我是一名优秀的程序员,十分优秀!