der er tabs i alle filerne coden jeg bruger til at finde det er denne
Reader in = new FileReader(fileName); while((ch=in.read())!= -1){
if (Character.isLetterOrDigit((char)ch)){ charakters+=1; totalchrs+=1; } if (Character.isWhitespace((char)ch)){ space+=1; totalSpaces+=1; } if (Character.LINE_SEPARATOR==(char)ch){ lines+=1; totalLines+=1; } }// end while in.close();
jeg kan over hoved ikke forestå at den ikke kan finde mellemrum i nogle filer
her er hele koden
import java.io.*;
class SourceStatistics {
int totalLines=0; int totalSpaces=0; int totalchrs=0; int antalFiler=0;
//*************************************************************************** public SourceStatistics() { getFiles(); } //*************************************************************************** public void getFiles(){ try{ File f = new File("."); File[] files = f.listFiles(); int i=0; for (i = 0; i<files.length; i++){ if(files[i].isFile()&files[i].getName().endsWith(".java")){ getStatistics(files[i].getName()); antalFiler+=1; } } System.out.println ("antal Filer = "+antalFiler); System.out.println ("linjer tilsammens = "+totalLines); System.out.println ("bogstaver tilsammens = "+totalchrs); System.out.println ("spaces tilsammens = "+totalSpaces);
}catch(Exception e){ System.out.println ("ups "+e); } } //*************************************************************************** public void getStatistics(String fileName){ System.out.println ("file "+fileName); long lines=0; long charakters=0; int ch; int space=0;
try{ Reader in = new FileReader(fileName); while((ch=in.read())!= -1){
if (Character.isLetterOrDigit((char)ch)){ charakters+=1; totalchrs+=1; } if (Character.isWhitespace((char)ch)){ space+=1; totalSpaces+=1; } if (Character.LINE_SEPARATOR==(char)ch){ lines+=1; totalLines+=1; } }// end while in.close(); System.out.println ("karakterer = "+charakters); // System.out.println ("spaces = "+space); System.out.println ("linjer = "+lines); System.out.println ("------------------------------------------------------ "); }catch(Exception e){ System.out.println ("Ups "+e); } } //*************************************************************************** public static void main(String args[]) { SourceStatistics mainFrame = new SourceStatistics();
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.