Topic: 编程出现错误 帮忙看下~(非法的表达式开始)

  Print this page

1.编程出现错误 帮忙看下~(非法的表达式开始) Copy to clipboard
Posted by: talentfly
Posted on: 2006-06-15 10:47


import java.io.*;
import java.util.*;
public class NewChose
{

public static void main(String[] args)
{
static ArrayList al=new ArrayList();
File f=new File("c:\\temp\\ch21");
NewChose.vistAllDirsAndFiles(f);
public static void visitAllDirsAndFiles(File dir)
{

for(dir.isDirectory())
{
String[] children=dir.list();
int len=children.length();
for(int i=0;i<len;i++)
{
visitAllDirsAndFiles(new File(dir, children[i]));
}
}
else
{
String name=dir.getName();
String sub=name.substring(name.length()-3,name.length());
if(sub.equals("txt"))
{
al.add(dir);
}
}
}
System.out.println(al.toString());

}
}

C:\javalianxi\NewFile\NewChose.java:8: 非法的表达式开始
static ArrayList al=new ArrayList();
^
C:\javalianxi\NewFile\NewChose.java:11: 非法的表达式开始
public static void visitAllDirsAndFiles(File dir)
^
2 错误
请各位多多关照~~~

2.Re:编程出现错误 帮忙看下~~ [Re: talentfly] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-06-15 11:43

21行那个“else”上面对应的if 呢?

3.Re:编程出现错误 帮忙看下~~ [Re: lisliefor] Copy to clipboard
Posted by: zcjl
Posted on: 2006-06-15 12:20

太多错误了……几乎就没有一处对的

4.Re:编程出现错误 帮忙看下~~ [Re: talentfly] Copy to clipboard
Posted by: talentfly
Posted on: 2006-06-15 14:31

啊,谢谢各位提点~小弟太菜了~希望别见笑

5.Re:编程出现错误 帮忙看下~~ [Re: talentfly] Copy to clipboard
Posted by: Skybus
Posted on: 2006-06-15 15:50

import java.io.*;
import java.util.*;

public class NewChoose {
  static ArrayList al = new ArrayList();

  public static void main(String[] args) {

    File f = new File("c:\\temp\\ch21");
    NewChoose.visitAllDirsAndFiles(f);

    System.out.println(al.toString());

  }

  public static void visitAllDirsAndFiles(File dir) {

    if (dir.isDirectory()) {
      String[] children = dir.list();

      int len = children.length;

      for (int i = 0; i < len; i++) {
        visitAllDirsAndFiles(new File(dir, children[i]));
      }
    } else {
      String name = dir.getName();
      String sub = name.substring(name.length() - 3, name.length());
      if (sub.equals("txt")) {
        al.add(dir);
      }
    }
  }
}

许多常识性错误,不再一一指出,自己对照着检查一下!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923