简体   繁体   English

如何导航 Java 中的图像文件对象数组?

[英]How do you navigate an array of image file objects in Java?

I am tasked to create navigation buttons for a simple image processing application, that navigate through a folder containing images.我的任务是为一个简单的图像处理应用程序创建导航按钮,该应用程序在包含图像的文件夹中导航。 I am required to create an array of file objects of a selected folder.我需要创建一个选定文件夹的文件对象数组。

The buttons have to be next and previous buttons, that navigate the next image within the array of file objects.按钮必须是下一个上一个按钮,用于导航文件对象数组中的下一个图像。 After the last image within the folder was reached, the next button has to loop to the first image and vice versa with the previous button.到达文件夹中的最后一张图像后,下一个按钮必须循环到第一张图像,反之亦然,上一个按钮。

I tried declaring an int[] array of the length of the number of files contained within a folder using the listFiles() method, but I received the error: cannot find symbol :我尝试使用listFiles()方法声明文件夹中包含的文件数长度的int[]数组,但收到错误:找不到符号

int[] file = new int[("/pictures").listFiles().length];

What would I need to do in order to be able to create an array of file objects of the length of the total number of files, which I would be able to navigate using buttons?为了能够创建文件总数长度的文件对象数组,我需要做什么,我可以使用按钮进行导航?

Your problem is calling listFiles on a String , rather than File object.您的问题是在String上调用listFiles ,而不是File object。 Try to modify your code as follows:尝试如下修改您的代码:

int[] file = new int[new java.io.File("/pictures").listFiles().length];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM