只能从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 methodfile.listfolders()
outputs null if called from myTextProcessor
class instance. However, changing the method tostatic
and calling it from amain()
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
最满意答案
更改
- (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 ...
-
Swift将PFQuery转换为TableView的String数组(Swift Converting PFQuery to String Array for TableView)[2021-06-19]
问题是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 ...
-
PFQuery按日期(PFQuery by date)[2022-03-21]
NSDate对象和Parse.com日期字段都有确切的时间,包括小时和分钟。 这意味着如果您正在寻找某一天发生的约会,则实际上您正在搜索日期范围:该特定日期的上午12:00至下午11:59。 如果您创建的NSDate没有明确的小时和分钟,Parse并不知道您的意思是“当天的所有日期” - 它通过填充小时和分钟并搜索确切时间来解释它。 你可以通过日期范围搜索解决这个问题。 这里是一个例子,说明如何从我的一个应用程序中执行此操作,并根据您的目的进行修改: //Create two dates for this ... -
TableView没有显示数据(TableView not showing data)[2022-08-31]
问题是你在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 ...
-
即使Parse服务器发生更改,PFQuery也始终返回相同的结果(PFQuery always return same results even though Parse server changed)[2024-02-16]
最后,我自己解决了问题。 我发现每当固定PFObject时,其字段都不会更新。 解决方案是在从服务器检索之前需要取消固定对象。 Event.unpinAllInBackground(events, block: { (success, error) -> Void in if error != nil { print(error?.localizedDescription) }else{ ... -
PFQuery没有获取对象ID(PFQuery not getting Object ID)[2022-02-13]
我认为问题在于您为用户获取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 ...