首页 \ 问答 \ 只能从main()读取文件夹/目录?(can only read folder/directory from main() ? listfiles() returns null?)

只能从main()读取文件夹/目录?(can only read folder/directory from main() ? listfiles() returns null?)

我正在x64 windows操作系统上使用jdk 1.8 x64开发Netbeans java项目我的问题是:“如果从我的TextProcessor类实例调用,则使用file.listfolders()方法读取目录的内容(仅限文件)。 ,将方法更改为static并从main()调用它可以完美地工作,所以它与权限无关,据我了解。

private List<String> get_files_paths(String data_path) {
    File folder = new File(data_path);
    List<String> full_paths = new ArrayList<String>();
    for (final File fileEntry : folder.listFiles()) {
        if (!fileEntry.isDirectory())
            full_paths.add(fileEntry.getAbsolutePath());
    }
    return full_paths;
}

提前致谢。


I'm working on a Netbeans java project using jdk 1.8 x64 on a x64 windows OS My problem is: "reading a directory's content (only files) with the method file.listfolders() outputs null if called from my TextProcessor class instance. However, changing the method to static and calling it from a main() works perfectly, so it has nothing to do with permissions as far as I understand.

private List<String> get_files_paths(String data_path) {
    File folder = new File(data_path);
    List<String> full_paths = new ArrayList<String>();
    for (final File fileEntry : folder.listFiles()) {
        if (!fileEntry.isDirectory())
            full_paths.add(fileEntry.getAbsolutePath());
    }
    return full_paths;
}

Thanks in advance.


原文:https://stackoverflow.com/questions/43803197
更新时间:2023-08-08 11:08

最满意答案

更改- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (nil == cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

    }
    cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"Name"];
    return cell;
}

Change - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (nil == cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

    }
    cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"Name"];
    return cell;
}

相关问答

更多
  • 为什么不在每次创建对象时使用默认值启动对象,并像您一样更改它。 一旦你想要获取没有@“DeleteObjectPin”的所有对象,你只需: PFQuery * objectQuery = [PFQuery queryWithClassName:@“Box”]; [objectQuery whereKey:equalTo:]; //然后用块或其他东西获取所有对象 Why not start your object with a default value every time you create it, a ...
  • 问题是userArray是一个NSArray。 NSArray是不可变的,意味着它无法更改。 因此它没有附加功能。 你想要的是一个NSMutableArray,可以更改并具有addObject函数。 var userArray:NSMutableArray = [] func loadParseData(){ var query : PFQuery = PFUser.query() query.findObjectsInBackgroundWithBlock { (obje ...
  • 您似乎没有正确初始化类,您需要设置要查询的类的名称 // Initialise the PFQueryTable tableview override init!(style: UITableViewStyle, className: String!) { super.init(style: style, className: className) } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) ...
  • NSOperation是一种选择。 如果你知道如何使用它, ReativeCocoa是另一个可以帮助你很容易地解决这个问题的方法。 然而,最简单的方法(和最简单的方法)可能是保持某种搜索状态,并将其用于仅应用最近的搜索结果。 var mostRecentSearchQuery: String = "" @IBAction func textFieldChanged (sender: AnyObject) { var queryString: String? if let textField: UIText ...
  • 更改- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier ...
  • NSDate对象和Parse.com日期字段都有确切的时间,包括小时和分钟。 这意味着如果您正在寻找某一天发生的约会,则实际上您正在搜索日期范围:该特定日期的上午12:00至下午11:59。 如果您创建的NSDate没有明确的小时和分钟,Parse并不知道您的意思是“当天的所有日期” - 它通过填充小时和分钟并搜索确切时间来解释它。 你可以通过日期范围搜索解决这个问题。 这里是一个例子,说明如何从我的一个应用程序中执行此操作,并根据您的目的进行修改: //Create two dates for this ...
  • 问题是你在tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int中返回0 tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int方法,不会呈现单元格。 您应该返回要渲染的单元格数,在您的情况下是您的firstname数组中的字符串数。 所以你的方法看起来像: override func tableView(tabl ...
  • 在您的第一条if语句中,您告诉服务器,如果发现对象时发生错误,或者查询发现了一些对象,则显示该警报。 但是假设用户输入了错误的代码,查询将返回一个空数组( 注意它不会返回nil,它是一个空数组 ),但不会有任何错误,因此执行了else块。 由于您的“phoneVerification”是一个数字,我们需要将codeTextField.text转换为NSNumber: let code = NSNumber(value:Int(codeTextField.text)!) let query = PFQuery ...
  • 最后,我自己解决了问题。 我发现每当固定PFObject时,其字段都不会更新。 解决方案是在从服务器检索之前需要取消固定对象。 Event.unpinAllInBackground(events, block: { (success, error) -> Void in if error != nil { print(error?.localizedDescription) }else{ ...
  • 我认为问题在于您为用户获取PFQuery的方式。 您应该使用特殊用户查询: var query = PFUser.query() 请参阅解析文档中的用户 - 查询 。 I think the problem lies in the way you're getting a PFQuery for the user. You should use the special user query: var query = PFUser.query() See Users - Querying, in the ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)