1
$\begingroup$

I tried to make the old code you suggested me a little faster by doing this changes:

Needs["JLink`"]

Scanner[archivo_String, palabra_String] :=
 JavaBlock@
  Module[{entrada, linea, numlinea, contiene, ruta}, numlinea = 1; 
   linea = ""; contiene = False;
   InstallJava[];
   ruta = JavaNew["java.io.File", archivo];
   entrada = JavaNew["java.util.Scanner", ruta];
   Print["Archivo: " <> ruta@getName[]];
   Print["Texto a buscar:" <> palabra];
   While[entrada@hasNext[], linea = entrada@nextLine[]; 
    If[JavaNew["java.lang.String", linea]@contains[palabra], 
     Print["Linea:" <> numlinea <> ":" <> linea];
     contiene = True]; numlinea++]; 
   If[! contiene, Print[ palabra <> " no se ha encontrado"]]]

But I get this and don't know why. It's not working cause "issue" appears several times.

enter image description here

Hope you can help me

$\endgroup$
1
$\begingroup$

The contains method requires a java.lang.String (or some other implementation of the CharSequence interface), not a Wolfram Language expression. Try using contains[MakeJavaObject@palabra] instead of contains[palabra]. There are more messages after that is fixed, I haven't looked at those.

$\endgroup$
1
  • $\begingroup$ Thank's. The messages are about StringJoin. ...Print["Linea " <> ToString[numlinea]<> ": " <> ToString[linea]]; fixed it. $\endgroup$ Sep 6 '20 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.