【发布时间】:2013-05-29 04:52:44
【问题描述】:
我看过一个关于这个问题的例子。但是当我尝试它时,它只是在这段代码中发生错误File f = new File(Uri.parse(uri.toString()));,只是说构造函数文件(Uri)是未定义的。我已经陷入这个错误很多天了。我不知道有什么问题,因为其他人可以工作。以下是建议代码
public class WiFiDirectBundle extends Serializable {
private String fileName;
private String mimeType;
private Long fileSize;
private byte[] fileContent;
public WiFiDirectBundle() {}
// adds a file to the bundle, given its URI
public void setFile(Uri uri) {
File f = new File(Uri.parse(uri.toString()));
fileName = f.getName();
mimeType = MimeTypeMap.getFileExtensionFromUrl(f.getAbsolutePath());
fileSize = f.length();
FileInputStream fin = new FileInputStream(f);
fileContent = new byte[(int) f.length()];
fin.read(fileContent);
}
// restores the file of the bundle, given its directory (change to whatever
// fits you better)
public String restoreFile(String baseDir) {
File f = new File(baseDir + "/" + fileName);
try {
FileOutputStream fos = new FileOutputStream(f);
if (fileContent != null) {
fos.write(fileContent);
}
fos.close();
return f.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public String getFileName() {
return fileName;
}
public String getMimeType() {
return mimeType;
}
public Long getFileSize() {
return fileSize;
}
}
这是原始问题: How to find file name of a file which is transferred via wifi direct mode in android? 另外我是Wifi Direct的初学者,我可以成功链接两个设备并传输文件,但我想链接更多设备并依次传输文件有人可以给我一些关于学习它的建议或一些关于如何做的例子。谢谢!
【问题讨论】:
-
我已经看到了这个问题(在我的问题中我也说过)。我已经尝试过了,但在我的问题中出现了错误,所以我想再次询问,看看谁能帮助我解决这个问题错误。谢谢
标签: android file-transfer wifi-direct