高手,您好:
我是一名学习软件工程的学生,现在,我正在做我的第一个Java作品。
希望得到高手的点拨:
下面我写的这个“查找本地文件”的代码:
package c_port_package;import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;public class CheckAndConfirmworker {
static C_port_Our_honor fileDS = null;
HashMap<String,String> fileset = null;
static ArrayList<String> thecommonfruitPath = new ArrayList<String>();
static ArrayList<String> thevideofruitPath = new ArrayList<String>();
static ArrayList<String> thecommonfruitFullname = new ArrayList<String>();
static ArrayList<String> thecommonfruitExtenName = new ArrayList<String>();
static ArrayList<String> thecommonfruitpreName = new ArrayList<String>();
static ArrayList<String> thecommonvideoExtenName = new ArrayList<String>();
static ArrayList<String> thevideoFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitpreName = new ArrayList<String>();
static ArrayList<String> thevideofruitFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitExtenName = new ArrayList<String>();
static int calc0 = 0;
static int calc1 = 0;
static File file = new File("D:\\");
static int j = 0;
static int t = 1; //获取文件扩展名
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
//获取去掉扩展名的文件名
public static String getpreFileName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
public static void main(String[] args){
for(int i = 0;i<2;i++){
System.out.println(thecommonfruitPath.get[i]);
}
}
static public ArrayList<String> findthecommonfruit(File file){
File[] files1 = null;
files1 = file.listFiles();
for(int i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthecommonfruit(files1[i]);
}
for(i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthevideofruit(files1[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files1[i].getPath().endsWith("ppt")||files1[i].getPath().endsWith("doc")||files1[i].getPath().endsWith("txt")||files1[i].getPath()
.endsWith("wps")||files1[i].getPath().endsWith("excel")||files1[i].getPath().endsWith("jude")||files1[i].getPath().endsWith("bmp")
||files1[i].getPath().endsWith("c")||files1[i].getPath().endsWith("cpp")||files1[i].getPath().endsWith("java")||files1[i].getPath().endsWith("js")
||files1[i].getPath().endsWith("asp")||files1[i].getPath().endsWith("jsp")||files1[i].getPath().endsWith("php")||files1[i].getPath().endsWith("pdf")
||files1[i].getPath().endsWith("jpeg")||files1[i].getPath().endsWith("gif")||files1[i].getPath().endsWith("html")||files1[i].getPath().endsWith("png")
||files1[i].getPath().endsWith("xls")||files1[i].getPath().endsWith("zip")){
thecommonfruitPath.add(files1[i].getAbsolutePath());
thecommonfruitFullname.add(files1[i].getName());
thecommonfruitpreName.add(getpreFileName(files1[i].getName()));
thecommonfruitExtenName.add(getExtensionName(files1[i].getName()));
++calc1;
}
}
}
return thecommonfruitPath;
}
static public ArrayList<String> findthevideofruit(File file){
File[] files2 = null;
files2 = file.listFiles();
for(int i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthecommonfruit(files2[i]);
}
for(i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthevideofruit(files2[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files2[i].getPath().endsWith("3GP")||files2[i].getPath().endsWith("mid")||files2[i].getPath().endsWith("mp4")||files2[i].getPath()
.endsWith("flash")||files2[i].getPath().endsWith("rm")||files2[i].getPath().endsWith("rmvb")||files2[i].getPath().endsWith("wma")
||files2[i].getPath().endsWith("avi")){
thevideofruitPath.add(files2[i].getAbsolutePath());
thevideofruitFullName.add(files2[i].getName());
thevideofruitpreName.add(getpreFileName(files2[i].getName()));
thevideofruitExtenName.add(getExtensionName(files2[i].getName()));
++calc1;
}
}
}
return thevideofruitPath;
}
public ArrayList<String> giveCsectorcommonFilepath(){
return thecommonfruitPath=findthecommonfruit(new File("C:"+File.separator));
}
public ArrayList<String> giveCsectorvideoFilepath(){
return thevideofruitPath=findthevideofruit(new File("C:"));
}
public ArrayList<String> giveDsectorcommonFilepath(){
return findthecommonfruit(new File("D:"+File.separator));
}
public ArrayList<String> giveDvideocommonFilepath(){
return findthevideofruit(new File("D:"+File.separator));
}
public ArrayList<String> giveEsectorcommonfilepath(){
return findthecommonfruit(new File("E:"+File.separator));
}
public ArrayList<String> giveEsectorvideofilepath(){
return findthevideofruit(new File("E:"+File.separator));
}
public ArrayList<String> giveFsectorcommonfilepath(){
return findthecommonfruit(new File("F:"+File.separator));
}
public static ArrayList<String> giveFsectorvideofilepath(){
return findthevideofruit(new File("F:"+File.separator));
}
} 上面的代码中,经过了长时间的调试,还是未能将上面代码中,在我的MyEclipse中的第52行代码里的错误:
希望得到诸位高手的点拨:
我上面的这个“第52行代码”中的错误,是由什么原因,造成的...?
怎么修改,能够将错误进行排出,并且,将本类文件的“查找本地文件”的功能,实现...?
谢谢高手的点拨!!
一百分奉上!!
一位日日夜夜向着理想奔跑的筑梦者
2013年8月11日早晨4点02分Java调试Java SE排查错误Java代码编译错误原因
我是一名学习软件工程的学生,现在,我正在做我的第一个Java作品。
希望得到高手的点拨:
下面我写的这个“查找本地文件”的代码:
package c_port_package;import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;public class CheckAndConfirmworker {
static C_port_Our_honor fileDS = null;
HashMap<String,String> fileset = null;
static ArrayList<String> thecommonfruitPath = new ArrayList<String>();
static ArrayList<String> thevideofruitPath = new ArrayList<String>();
static ArrayList<String> thecommonfruitFullname = new ArrayList<String>();
static ArrayList<String> thecommonfruitExtenName = new ArrayList<String>();
static ArrayList<String> thecommonfruitpreName = new ArrayList<String>();
static ArrayList<String> thecommonvideoExtenName = new ArrayList<String>();
static ArrayList<String> thevideoFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitpreName = new ArrayList<String>();
static ArrayList<String> thevideofruitFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitExtenName = new ArrayList<String>();
static int calc0 = 0;
static int calc1 = 0;
static File file = new File("D:\\");
static int j = 0;
static int t = 1; //获取文件扩展名
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
//获取去掉扩展名的文件名
public static String getpreFileName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
public static void main(String[] args){
for(int i = 0;i<2;i++){
System.out.println(thecommonfruitPath.get[i]);
}
}
static public ArrayList<String> findthecommonfruit(File file){
File[] files1 = null;
files1 = file.listFiles();
for(int i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthecommonfruit(files1[i]);
}
for(i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthevideofruit(files1[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files1[i].getPath().endsWith("ppt")||files1[i].getPath().endsWith("doc")||files1[i].getPath().endsWith("txt")||files1[i].getPath()
.endsWith("wps")||files1[i].getPath().endsWith("excel")||files1[i].getPath().endsWith("jude")||files1[i].getPath().endsWith("bmp")
||files1[i].getPath().endsWith("c")||files1[i].getPath().endsWith("cpp")||files1[i].getPath().endsWith("java")||files1[i].getPath().endsWith("js")
||files1[i].getPath().endsWith("asp")||files1[i].getPath().endsWith("jsp")||files1[i].getPath().endsWith("php")||files1[i].getPath().endsWith("pdf")
||files1[i].getPath().endsWith("jpeg")||files1[i].getPath().endsWith("gif")||files1[i].getPath().endsWith("html")||files1[i].getPath().endsWith("png")
||files1[i].getPath().endsWith("xls")||files1[i].getPath().endsWith("zip")){
thecommonfruitPath.add(files1[i].getAbsolutePath());
thecommonfruitFullname.add(files1[i].getName());
thecommonfruitpreName.add(getpreFileName(files1[i].getName()));
thecommonfruitExtenName.add(getExtensionName(files1[i].getName()));
++calc1;
}
}
}
return thecommonfruitPath;
}
static public ArrayList<String> findthevideofruit(File file){
File[] files2 = null;
files2 = file.listFiles();
for(int i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthecommonfruit(files2[i]);
}
for(i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthevideofruit(files2[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files2[i].getPath().endsWith("3GP")||files2[i].getPath().endsWith("mid")||files2[i].getPath().endsWith("mp4")||files2[i].getPath()
.endsWith("flash")||files2[i].getPath().endsWith("rm")||files2[i].getPath().endsWith("rmvb")||files2[i].getPath().endsWith("wma")
||files2[i].getPath().endsWith("avi")){
thevideofruitPath.add(files2[i].getAbsolutePath());
thevideofruitFullName.add(files2[i].getName());
thevideofruitpreName.add(getpreFileName(files2[i].getName()));
thevideofruitExtenName.add(getExtensionName(files2[i].getName()));
++calc1;
}
}
}
return thevideofruitPath;
}
public ArrayList<String> giveCsectorcommonFilepath(){
return thecommonfruitPath=findthecommonfruit(new File("C:"+File.separator));
}
public ArrayList<String> giveCsectorvideoFilepath(){
return thevideofruitPath=findthevideofruit(new File("C:"));
}
public ArrayList<String> giveDsectorcommonFilepath(){
return findthecommonfruit(new File("D:"+File.separator));
}
public ArrayList<String> giveDvideocommonFilepath(){
return findthevideofruit(new File("D:"+File.separator));
}
public ArrayList<String> giveEsectorcommonfilepath(){
return findthecommonfruit(new File("E:"+File.separator));
}
public ArrayList<String> giveEsectorvideofilepath(){
return findthevideofruit(new File("E:"+File.separator));
}
public ArrayList<String> giveFsectorcommonfilepath(){
return findthecommonfruit(new File("F:"+File.separator));
}
public static ArrayList<String> giveFsectorvideofilepath(){
return findthevideofruit(new File("F:"+File.separator));
}
} 上面的代码中,经过了长时间的调试,还是未能将上面代码中,在我的MyEclipse中的第52行代码里的错误:
希望得到诸位高手的点拨:
我上面的这个“第52行代码”中的错误,是由什么原因,造成的...?
怎么修改,能够将错误进行排出,并且,将本类文件的“查找本地文件”的功能,实现...?
谢谢高手的点拨!!
一百分奉上!!
一位日日夜夜向着理想奔跑的筑梦者
2013年8月11日早晨4点02分Java调试Java SE排查错误Java代码编译错误原因
解决方案 »
- 新手请教前辈几个问题
- 请教一java程序
- 重新开贴:求java发展史上的名人,有趣的故事!
- 在下写的一个绚丽多彩的3D花篮,现在公布源代码,希望和大家共同切磋交流:)
- 菜鸟关于string类取数的问题
- 关于Jbuilder中的LookAndFeel(系统显示风格的问题)
- 帮帮忙,多谢!在Java中怎样对一个double数取有效位数?
- java正则表达,该怎么理解才好??
- 急急急!为甚么Eclipse里面没有intersects(Rectangle r)这个方法,但查API文档又有!!
- 谢谢各位大神
- 求各位帮忙 ! 谢谢谢谢谢
- 求神仙解释while里面的内容第一次i= 0后查找index==-1,就break了,就跳出while了,i怎么可能还有机会再累加呢
main函数是程序入口,意味着你想要做的事情,都需要在main里做,你注意下你现在main里做了什么:仅仅是循环了下一个List而已。。你想要查找本地文件,那你要调用对应的方法才行啊,方法你都写了,但是你没有在main里调用,怎么会有结果呢。
System.out.println(findthecommonfruit(file).get[i]);
}
我猜是该变量无get方法
public static void main(String[] args) {
findthecommonfruit(new File("F:\\music"));//这里需要执行这个调用方法,并给出需要搜索的路径
//循环遍历,需要用size()方法
for (int i = 0; i < thecommonfruitPath.size(); i++) {
System.out.println(thecommonfruitPath.get(i));
}
}
package c_port_package;import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;public class CheckAndConfirmworker {
static C_port_Our_honor fileDS = null;
HashMap<String,String> fileset = null;
static ArrayList<String> thecommonfruitPath = new ArrayList<String>();
static ArrayList<String> thevideofruitPath = new ArrayList<String>();
static ArrayList<String> thecommonfruitFullname = new ArrayList<String>();
static ArrayList<String> thecommonfruitExtenName = new ArrayList<String>();
static ArrayList<String> thecommonfruitpreName = new ArrayList<String>();
static ArrayList<String> thecommonvideoExtenName = new ArrayList<String>();
static ArrayList<String> thevideoFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitpreName = new ArrayList<String>();
static ArrayList<String> thevideofruitFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitExtenName = new ArrayList<String>();
static int calc0 = 0;
static int calc1 = 0;
static File file = new File("F:\\");
static int j = 0;
static int t = 1; //获取文件扩展名
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
//获取去掉扩展名的文件名
public static String getpreFileName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
public static void main(String[] args){
findthecommonfruit(file);
for(int i = 0;i<2;i++){
System.out.println(thecommonfruitPath.get(i));
}
}
static public ArrayList<String> findthecommonfruit(File file){
File[] files1 = null;
files1 = file.listFiles();
for(int i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthecommonfruit(files1[i]);
}
for(i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthevideofruit(files1[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files1[i].getPath().endsWith("ppt")||files1[i].getPath().endsWith("doc")||files1[i].getPath().endsWith("txt")||files1[i].getPath()
.endsWith("wps")||files1[i].getPath().endsWith("excel")||files1[i].getPath().endsWith("jude")||files1[i].getPath().endsWith("bmp")
||files1[i].getPath().endsWith("c")||files1[i].getPath().endsWith("cpp")||files1[i].getPath().endsWith("java")||files1[i].getPath().endsWith("js")
||files1[i].getPath().endsWith("asp")||files1[i].getPath().endsWith("jsp")||files1[i].getPath().endsWith("php")||files1[i].getPath().endsWith("pdf")
||files1[i].getPath().endsWith("jpeg")||files1[i].getPath().endsWith("gif")||files1[i].getPath().endsWith("html")||files1[i].getPath().endsWith("png")
||files1[i].getPath().endsWith("xls")||files1[i].getPath().endsWith("zip")){
thecommonfruitPath.add(files1[i].getAbsolutePath());
thecommonfruitFullname.add(files1[i].getName());
thecommonfruitpreName.add(getpreFileName(files1[i].getName()));
thecommonfruitExtenName.add(getExtensionName(files1[i].getName()));
++calc1;
}
}
}
return thecommonfruitPath;
}
static public ArrayList<String> findthevideofruit(File file){
File[] files2 = null;
files2 = file.listFiles();
for(int i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthecommonfruit(files2[i]);
}
for(i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthevideofruit(files2[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files2[i].getPath().endsWith("3GP")||files2[i].getPath().endsWith("mid")||files2[i].getPath().endsWith("mp4")||files2[i].getPath()
.endsWith("flash")||files2[i].getPath().endsWith("rm")||files2[i].getPath().endsWith("rmvb")||files2[i].getPath().endsWith("wma")
||files2[i].getPath().endsWith("avi")){
thevideofruitPath.add(files2[i].getAbsolutePath());
thevideofruitFullName.add(files2[i].getName());
thevideofruitpreName.add(getpreFileName(files2[i].getName()));
thevideofruitExtenName.add(getExtensionName(files2[i].getName()));
++calc1;
}
}
}
return thevideofruitPath;
}
public ArrayList<String> giveCsectorcommonFilepath(){
return thecommonfruitPath=findthecommonfruit(new File("C:"+File.separator));
}
public ArrayList<String> giveCsectorvideoFilepath(){
return thevideofruitPath=findthevideofruit(new File("C:"));
}
public ArrayList<String> giveDsectorcommonFilepath(){
return findthecommonfruit(new File("D:"+File.separator));
}
public ArrayList<String> giveDvideocommonFilepath(){
return findthevideofruit(new File("D:"+File.separator));
}
public ArrayList<String> giveEsectorcommonfilepath(){
return findthecommonfruit(new File("E:"+File.separator));
}
public ArrayList<String> giveEsectorvideofilepath(){
return findthevideofruit(new File("E:"+File.separator));
}
public ArrayList<String> giveFsectorcommonfilepath(){
return findthecommonfruit(new File("F:"+File.separator));
}
public static ArrayList<String> giveFsectorvideofilepath(){
return findthevideofruit(new File("F:"+File.separator));
}
} 但是,运行后的错误提示为:
希望诸位高手能够告诉我:
这里的错误,是什么原因...?
谢谢诸位高手!!
static C_port_Our_honor fileDS = null;
C_port_Our_honor fileDSz这个东西没有类型
public ArrayList<String> giveCsectorcommonFilepath(){
return thecommonfruitPath=findthecommonfruit(new File("C:"+File.separator));
}
public ArrayList<String> giveCsectorvideoFilepath(){
return thevideofruitPath=findthevideofruit(new File("C:"));
}
public ArrayList<String> giveDsectorcommonFilepath(){
return findthecommonfruit(new File("D:"+File.separator));
}
public ArrayList<String> giveDvideocommonFilepath(){
return findthevideofruit(new File("D:"+File.separator));
}
public ArrayList<String> giveEsectorcommonfilepath(){
return findthecommonfruit(new File("E:"+File.separator));
}
public ArrayList<String> giveEsectorvideofilepath(){
return findthevideofruit(new File("E:"+File.separator));
}
public ArrayList<String> giveFsectorcommonfilepath(){
return findthecommonfruit(new File("F:"+File.separator));
}把这些方法设置成static
main方法改为
thecommonfruitPath = giveFsectorcommonfilepath();
for(int i = 0;i<2;i++){
System.out.println(thecommonfruitPath.get(i));
}
这样即可获得F盘里你需要找到的文件
这里是弟我最新的修改进度:
package c_port_package;import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;public class CheckAndConfirmworker {
static C_port_Our_honor fileDS = null;
HashMap<String,String> fileset = null;
static ArrayList<String> thecommonfruitPath = new ArrayList<String>();
static ArrayList<String> thevideofruitPath = new ArrayList<String>();
static ArrayList<String> thecommonfruitFullname = new ArrayList<String>();
static ArrayList<String> thecommonfruitExtenName = new ArrayList<String>();
static ArrayList<String> thecommonfruitpreName = new ArrayList<String>();
static ArrayList<String> thecommonvideoExtenName = new ArrayList<String>();
static ArrayList<String> thevideoFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitpreName = new ArrayList<String>();
static ArrayList<String> thevideofruitFullName = new ArrayList<String>();
static ArrayList<String> thevideofruitExtenName = new ArrayList<String>();
static int calc0 = 0;
static int calc1 = 0;
static File file = new File("F:\\");
static int j = 0;
static int t = 1; //获取文件扩展名
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
}
//获取去掉扩展名的文件名
public static String getpreFileName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot >-1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
public static void main(String[] args){
thecommonfruitPath = findthecommonfruit(file);
for(int i = 0;i<2;i++){
System.out.println(thecommonfruitPath.get(i));
}
}
static public ArrayList<String> findthecommonfruit(File file){
File[] files1 = null;
files1 = file.listFiles();
for(int i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthecommonfruit(files1[i]);
}
for(i=0;i<files1.length;i++){
if(files1[i].isDirectory()){
findthevideofruit(files1[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files1[i].getPath().endsWith("ppt")||files1[i].getPath().endsWith("doc")||files1[i].getPath().endsWith("txt")||files1[i].getPath()
.endsWith("wps")||files1[i].getPath().endsWith("excel")||files1[i].getPath().endsWith("jude")||files1[i].getPath().endsWith("bmp")
||files1[i].getPath().endsWith("c")||files1[i].getPath().endsWith("cpp")||files1[i].getPath().endsWith("java")||files1[i].getPath().endsWith("js")
||files1[i].getPath().endsWith("asp")||files1[i].getPath().endsWith("jsp")||files1[i].getPath().endsWith("php")||files1[i].getPath().endsWith("pdf")
||files1[i].getPath().endsWith("jpeg")||files1[i].getPath().endsWith("gif")||files1[i].getPath().endsWith("html")||files1[i].getPath().endsWith("png")
||files1[i].getPath().endsWith("xls")||files1[i].getPath().endsWith("zip")){
thecommonfruitPath.add(files1[i].getAbsolutePath());
thecommonfruitFullname.add(files1[i].getName());
thecommonfruitpreName.add(getpreFileName(files1[i].getName()));
thecommonfruitExtenName.add(getExtensionName(files1[i].getName()));
++calc1;
}
}
}
return thecommonfruitPath;
}
static public ArrayList<String> findthevideofruit(File file){
File[] files2 = null;
files2 = file.listFiles();
for(int i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthecommonfruit(files2[i]);
}
for(i=0;i<files2.length;i++){
if(files2[i].isDirectory()){
findthevideofruit(files2[i]);
++calc0;
}
//System.out.println(files[i]);
else if(files2[i].getPath().endsWith("3GP")||files2[i].getPath().endsWith("mid")||files2[i].getPath().endsWith("mp4")||files2[i].getPath()
.endsWith("flash")||files2[i].getPath().endsWith("rm")||files2[i].getPath().endsWith("rmvb")||files2[i].getPath().endsWith("wma")
||files2[i].getPath().endsWith("avi")){
thevideofruitPath.add(files2[i].getAbsolutePath());
thevideofruitFullName.add(files2[i].getName());
thevideofruitpreName.add(getpreFileName(files2[i].getName()));
thevideofruitExtenName.add(getExtensionName(files2[i].getName()));
++calc1;
}
}
}
return thevideofruitPath;
}
public static ArrayList<String> giveCsectorcommonFilepath(){
return thecommonfruitPath=findthecommonfruit(new File("C:"+File.separator));
}
public static ArrayList<String> giveCsectorvideoFilepath(){
return thevideofruitPath=findthevideofruit(new File("C:"));
}
public static ArrayList<String> giveDsectorcommonFilepath(){
return findthecommonfruit(new File("D:"+File.separator));
}
public static ArrayList<String> giveDvideocommonFilepath(){
return findthevideofruit(new File("D:"+File.separator));
}
public static ArrayList<String> giveEsectorcommonfilepath(){
return findthecommonfruit(new File("E:"+File.separator));
}
public static ArrayList<String> giveEsectorvideofilepath(){
return findthevideofruit(new File("E:"+File.separator));
}
public static ArrayList<String> giveFsectorcommonfilepath(){
return findthecommonfruit(new File("F:"+File.separator));
}
public static ArrayList<String> giveFsectorvideofilepath(){
return findthevideofruit(new File("F:"+File.separator));
}
} 但是,得到的运行结果是:
并且,wuyanxue哥,上面您说的“C_port_Our_honor”类文件的内容如下:
这个类文件的代码如下:
package c_port_package;public class C_port_Our_honor {
static String filePath = null;
static String fileexpandName = null;
static String filepreName = null;
}
希望能够得到wuyanxue哥的指导:
这里的问题,出在什么位置...?
所以,不能使用下角标的那个符号,应该使用函数调用的方法。
也就是说,不能用方括号,应该用圆括号。以为你是调用的get方法(函数)。
System.out.println(thecommonfruitPath.get(i));
import java.util.ArrayList;public class CheckAndConfirmworker {
private static ArrayList<String> commonPath = new ArrayList<String>();
private static ArrayList<String> videoPath = new ArrayList<String>();
private static ArrayList<String> commonFullname = new ArrayList<String>();
private static ArrayList<String> commonExtendName = new ArrayList<String>();
private static ArrayList<String> commonPreName = new ArrayList<String>(); private static ArrayList<String> videoFullName = new ArrayList<String>();
private static ArrayList<String> videoPreName = new ArrayList<String>();
private static ArrayList<String> videoExtenName = new ArrayList<String>(); public static void main(String[] args) { try {
// 获取文件路径
File file = new File("D:\\Test");
commonPath = findCommon(file);
} catch (Exception e) {
e.printStackTrace();
//Do something.
}
for (int i = 0; i < commonPath.size(); i++) {
System.out.println(commonPath.get(i));
}
} /**
* 普通文件取得
*
* @param file
* @return ArrayList
*/
public static ArrayList<String> findCommon(File file) {
File[] normalFiles = null;
normalFiles = file.listFiles();
for (int i = 0; i < normalFiles.length; i++) { for (i = 0; i < normalFiles.length; i++) {
if (normalFiles[i].isDirectory()) {
findCommon(normalFiles[i]);
findVideo(normalFiles[i]);
} else if (normalFiles[i].getPath().toLowerCase().endsWith("ppt")
|| normalFiles[i].getPath().toLowerCase().endsWith("doc")
|| normalFiles[i].getPath().toLowerCase().endsWith("txt")
|| normalFiles[i].getPath().toLowerCase().endsWith("wps")
|| normalFiles[i].getPath().toLowerCase().endsWith("excel")
|| normalFiles[i].getPath().toLowerCase().endsWith("jude")
|| normalFiles[i].getPath().toLowerCase().endsWith("bmp")
|| normalFiles[i].getPath().toLowerCase().endsWith("c")
|| normalFiles[i].getPath().toLowerCase().endsWith("cpp")
|| normalFiles[i].getPath().toLowerCase().endsWith("java")
|| normalFiles[i].getPath().toLowerCase().endsWith("js")
|| normalFiles[i].getPath().toLowerCase().endsWith("asp")
|| normalFiles[i].getPath().toLowerCase().endsWith("jsp")
|| normalFiles[i].getPath().toLowerCase().endsWith("php")
|| normalFiles[i].getPath().toLowerCase().endsWith("pdf")
|| normalFiles[i].getPath().toLowerCase().endsWith("jpeg")
|| normalFiles[i].getPath().toLowerCase().endsWith("gif")
|| normalFiles[i].getPath().toLowerCase().endsWith("html")
|| normalFiles[i].getPath().toLowerCase().endsWith("png")
|| normalFiles[i].getPath().toLowerCase().endsWith("xls")
|| normalFiles[i].getPath().toLowerCase().endsWith("zip")) {
commonPath.add(normalFiles[i].getAbsolutePath());
commonFullname.add(normalFiles[i].getName());
commonPreName.add(getPreFileName(normalFiles[i].getName()));
commonExtendName.add(getExtensionName(normalFiles[i].getName())); }
}
}
return commonPath;
} /**
* 音视频文件取得
*
* @param file
* @return ArrayList
*/
public static ArrayList<String> findVideo(File file) {
File[] videoFiles = null;
videoFiles = file.listFiles();
for (int i = 0; i < videoFiles.length; i++) { for (i = 0; i < videoFiles.length; i++) {
if (videoFiles[i].isDirectory()) {
findCommon(videoFiles[i]);
findVideo(videoFiles[i]);
} else if (videoFiles[i].getPath().toLowerCase().endsWith("3gp")
|| videoFiles[i].getPath().toLowerCase().endsWith("mid")
|| videoFiles[i].getPath().toLowerCase().endsWith("mp4")
|| videoFiles[i].getPath().toLowerCase().endsWith("flash")
|| videoFiles[i].getPath().toLowerCase().endsWith("rm")
|| videoFiles[i].getPath().toLowerCase().endsWith("rmvb")
|| videoFiles[i].getPath().toLowerCase().endsWith("wma")
|| videoFiles[i].getPath().toLowerCase().endsWith("avi")) {
videoPath.add(videoFiles[i].getAbsolutePath());
videoFullName.add(videoFiles[i].getName());
videoPreName.add(getPreFileName(videoFiles[i].getName()));
videoExtenName.add(getExtensionName(videoFiles[i].getName()));
}
}
}
return videoPath;
} /**
* 获取文件扩展名
*
* @param filename
* @return String
*/
public static String getExtensionName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length() - 1))) {
return filename.substring(dot + 1);
}
}
return filename;
} /**
* 获取去掉扩展名的文件名
*
* @param filename
* @return String
*/
public static String getPreFileName(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}}
改了下,你看看吧,可能很多地方还没有考虑到。
最近,确实...
是一段“黑白两色”“挥汗如雨”的日子....
弟我先将分数放下,假装死一回哥为弟我的问题,花费的时间最长,弟我,就将分数,多划给假装死一会哥一些了...
希望诸位高手能够理解!!
诸位高手和CSDN对于弟我的帮助,今后,弟我成为人物之后,再回报!!
谢谢诸位高手!!
对不起!!
假装死一会儿哥!!
希望您能够包涵弟我的“小BUG”,这几天,确实,很疲惫...
来日,再报诸位高手的点拨之情!!
诸位高手,等待弟我的成长吧!!