小编Col*_*non的帖子

网页搜索Android应用程序

作为我最后一年项目的一部分,我正在设计一个需要进行网络抓取的Android应用程序.我对此没有任何经验,所以我想知道是否有人知道他们想要分享的任何好的链接/教程.

编辑:我正在尝试将应用程序登录到站点并将详细信息从手机上传到站点.

android web-scraping

2
推荐指数
1
解决办法
2万
查看次数

使用 JFileChooser - 访问所选文件

有一段时间没有写代码了,所以我觉得我有点生疏了。我正在尝试构建一个应用程序,让用户选择一个文件作为输入。以下代码是我目前所拥有的:

JButton btnFile = new JButton("Select Excel File");
btnFile.addActionListener(new ActionListener() {
    //Handle open button action.
    public void actionPerformed(ActionEvent e) {
        final JFileChooser fc = new JFileChooser(); 
        int returnVal = fc.showOpenDialog(frmRenamePdfs);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            System.out.println("File: " + file.getName() + ".");    
        } else {
            System.out.println("Open command cancelled by user.");
        }
        System.out.println(returnVal);
    }
});
Run Code Online (Sandbox Code Playgroud)

我似乎无法弄清楚如何从侦听器外部访问“文件”,即在创建 GUI 其余部分的函数中。我在启动文件选择器的按钮旁边有一个空白文本标签,所以我想要做的是存储文件,并将文本标签的文本设置为文件名。

java swing scope jfilechooser

2
推荐指数
1
解决办法
2万
查看次数

使用缓冲区将http请求响应转换为Android中的字符串 - 未获得完整响应

我正在开发一个发布到网站的应用程序,我正在尝试将实体响应存储为字符串.但是,字符串似乎只包含一小部分响应,大约35行左右.我想知道它是否与缓冲区溢出有关但我真的不确定.我的代码如下:

static String getResponseBody(HttpResponse response) throws IllegalStateException, IOException{

    String content = null;
    HttpEntity entity = response.getEntity();

    if (entity != null) 
    {
        InputStream is = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = br.readLine()) != null) 
        {
            if(isBlankString(line) == false)
            {
            sb.append(line + "\n");
            }
        }
        br.close();
        content = sb.toString();
    }
    return content; 
Run Code Online (Sandbox Code Playgroud)

isBlankString只是注意一条线是否包含任何字符,因为响应中有很多空白行让我烦恼.我有一个问题,即无论有没有得到整个回应.任何人都知道发生了什么或如何解决这个问题?

谢谢

string android httpresponse buffer-overflow bufferedreader

1
推荐指数
1
解决办法
3234
查看次数