Exemplo n.º 1
0
  /**
   * Load the dcu ids from a file into a vector
   *
   * @param name The name of the file
   * @return The output vector
   */
  private static ArrayList<Integer> loadFile(String name)
      throws java.io.FileNotFoundException, java.io.IOException {
    File inputFile;
    FileReader in;
    int i;
    String s = "";
    int c;
    boolean stop;
    ArrayList<String> lines = new ArrayList<String>();
    ArrayList<Integer> v = new ArrayList<Integer>();

    in = new FileReader(name);
    stop = false;
    c = in.read();
    while (c != -1) {
      if (c != '\n') {
        s = s + (char) c;
      } else {
        if (!s.equals("")) lines.add(s);
        s = "";
      }
      c = in.read();
    }
    in.close();

    for (String line : lines) {
      String[] result = line.split(" ");
      v.add(Integer.parseInt(result[5]));
    }

    return v;
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    try {
      FileReader fr = new FileReader("a3.txt");
      int c = fr.read();

      Hashtable<String, Integer> map = new Hashtable<>();

      // First gift
      int house = 1;
      String position = "100-100";
      map.put(position, 1);

      while (c != -1) {
        char direction = (char) c;
        position = updatePosition(position, direction);

        // Update map
        if (map.get(position) == null) {
          house++;
          map.put(position, 1);
        } else {
          map.put(position, map.get(position) + 1);
        }

        c = fr.read();
      }

      System.out.println(house);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private final synchronized void init() {
    char[] buffer = new char[1024];

    String newName = mHeadsetName;
    int newState = mHeadsetState;
    mPrevHeadsetState = mHeadsetState;

    if (LOG) Slog.v(TAG, "init()");

    for (int i = 0; i < MAX_AUDIO_PORTS; i++) {
      try {
        FileReader file = new FileReader(uEventInfo[i][1]);
        int len = file.read(buffer, 0, 1024);
        file.close();
        newState = Integer.valueOf((new String(buffer, 0, len)).trim());

        file = new FileReader(uEventInfo[i][2]);
        len = file.read(buffer, 0, 1024);
        file.close();
        newName = new String(buffer, 0, len).trim();

        if (newState > 0) {
          updateState(newName, newState);
        }

      } catch (FileNotFoundException e) {
        Slog.w(TAG, "This kernel does not have wired headset support");
      } catch (Exception e) {
        Slog.e(TAG, "", e);
      }
    }
  }
Exemplo n.º 4
0
  public void load() {

    int lasttime = 0;
    int currenttime = 0;
    TimedMessage currentMessage = new TimedMessage();

    String word = "";
    char caract;

    if (f == null) return;
    try {
      // bon, pas super bo, mais ressort avec le return de fin de fichier
      while (true) {
        // lit premier caractere de la ligne courante, si fin de fichier, return
        if ((caract = (char) f.read()) == (char) (-1)) {
          parsedFile.put(new Integer(lasttime), currentMessage);
          indexmax = lasttime;
          Atom[] max = {Atom.newAtom("/indexmax"), Atom.newAtom(indexmax)};
          outlet(2, max);
          return;
        }

        // recherche indice temps
        word = "";
        while (caract != ' ') {
          word += caract;
          caract = (char) f.read();
        }

        currenttime = Integer.parseInt(word);

        // si temps courant > ligne precedente -> enregistre messages temps precedent
        if (currenttime > lasttime) {
          parsedFile.put(new Integer(lasttime), currentMessage);
          lasttime = currenttime;
          currentMessage = new TimedMessage();
        }

        // recupere phrase courante
        word = "";
        caract = (char) f.read();
        while (caract != '\n') {
          word += caract;
          caract = (char) f.read();
        }
        currentMessage.addMessage(Atom.parse(word));
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 5
0
  public static String getWord(FileReader in) throws IOException {
    // returns the next word found
    final int MaxLen = 255;
    int c, n = 0;
    char[] word = new char[MaxLen];
    // read over non-letters
    while (!Character.isLetter((char) (c = in.read())) && (c != -1)) ;
    // empty while body
    if (c == -1) return ""; // no letter found

    word[n++] = (char) c;
    while (Character.isLetter(c = in.read())) if (n < MaxLen) word[n++] = (char) c;
    return new String(word, 0, n);
  } // end getWord
Exemplo n.º 6
0
    public Xv4htEntityResolver() {
      try {
        FileReader myIn = new FileReader(catalog);
        while (true) {
          int c;
          String publicID = "";
          String systemID = "";

          while ((c = myIn.read()) != '\"') {
            if (c == -1) {
              break;
            }
          }
          if (c == -1) {
            break;
          }
          while ((c = myIn.read()) != '\"') {
            publicID += (char) c;
            if (c == -1) {
              break;
            }
          }
          if (c == -1) {
            break;
          }

          while ((c = myIn.read()) != '\"') {
            if (c == -1) {
              break;
            }
          }
          if (c == -1) {
            break;
          }
          while ((c = myIn.read()) != '\"') {
            systemID += (char) c;
            if (c == -1) {
              break;
            }
          }
          if (c == -1) {
            break;
          }

          entities.put(publicID, systemID);
        }
      } catch (java.io.IOException e) {
      }
    }
Exemplo n.º 7
0
 private String readFile(File target) throws IOException {
   FileReader fr = new FileReader(target);
   try {
     StringBuilder sb = new StringBuilder();
     char[] buf = new char[8192];
     int read = fr.read(buf);
     while (read >= 0) {
       sb.append(buf, 0, read);
       read = fr.read(buf);
     }
     return sb.toString();
   } finally {
     fr.close();
   }
 }
Exemplo n.º 8
0
 public static void main(String[] args) {
   System.err.println("Checking FSL path in " + args[0]);
   StringBuffer bf = new StringBuffer();
   try {
     FileReader fr = new FileReader(args[0]);
     int c;
     do {
       c = fr.read();
       bf.append((char) c);
     } while (c != -1);
     FSLNSResolver nsr = new FSLNSResolver();
     nsr.addPrefixBinding("a", "http://a#");
     nsr.addPrefixBinding("b", "http://b#");
     nsr.addPrefixBinding("c", "http://c#");
     nsr.addPrefixBinding("d", "http://d#");
     nsr.addPrefixBinding("e", "http://e#");
     nsr.addPrefixBinding("f", "http://f#");
     nsr.addPrefixBinding("n", "http://n#");
     nsr.addPrefixBinding("dc", "http://dc#");
     nsr.addPrefixBinding("xsd", "http://xsd#");
     nsr.addPrefixBinding("rdf", "http://rdf#");
     nsr.addPrefixBinding("foaf", "http://foaf#");
     nsr.addPrefixBinding("r", "http://r#");
     nsr.addPrefixBinding("", "http://DD#"); // default NS
     System.out.println(
         "serialization:  "
             + FSLPath.pathFactory(bf.substring(0, bf.length() - 1), nsr, FSLPath.NODE_STEP)
                 .serialize()
             + "\n");
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Exemplo n.º 9
0
 public static String getStringFromFile(String file) throws IOException {
   char[] data = null;
   FileReader fr = null;
   try {
     File f = new File(file);
     int max = (int) f.length(); // Will overshoot for multi-byte characters
     char[] tmp = new char[max];
     fr = new FileReader(f);
     int count = 0;
     while (count < max) {
       int actual = fr.read(tmp, count, max - count);
       if (actual == -1) break;
       count += actual;
     }
     if (count == max) {
       data = tmp;
     } else {
       data = new char[count];
       System.arraycopy(tmp, 0, data, 0, count);
     }
   } catch (IOException e) {
     throw e;
   } finally {
     if (fr != null) {
       try {
         fr.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
   return new String(data);
 }
Exemplo n.º 10
0
 public static void main(String[] args) {
   try {
     if (args.length != 1) throw new IllegalArgumentException("Wrong number of arguments");
     FileReader in = new FileReader(args[0]);
     HardcopyWriter out = null;
     Frame f = new Frame("PrintFile: " + args[0]);
     f.setSize(200, 50);
     f.show();
     try {
       out = new HardcopyWriter(f, args[0], 10, .75, .75, .75, .75);
     } catch (HardcopyWriter.PrintCanceledException e) {
       System.exit(0);
     }
     f.setVisible(false);
     char[] buffer = new char[4096];
     int numchars;
     while ((numchars = in.read(buffer)) != -1) out.write(buffer, 0, numchars);
     out.close();
   } catch (Exception e) {
     System.err.println(e);
     System.err.println("Usage: java HardcopyWriter$PrintFile <filename>");
     System.exit(1);
   }
   System.exit(0);
 }
Exemplo n.º 11
0
 /** Reads everything in the file in. Used by constructor. */
 public void readEverything() {
   // String line = new String();
   while (offset < size) {
     try {
       FileReader in = new FileReader(f);
       offset += in.read(data, offset, size);
       in.close();
       // line = new String(data);
     } catch (Exception ex) {
       System.out.println("FileIO.readEverything");
       System.out.println(ex);
       System.exit(0);
     }
   } // end of while
   // now hack it up into the string array
   int i, stra = 0;
   char[] str = new char[80]; // 80 in the max number of characters on a line
   int strc = 0;
   for (i = 0; i < size; i++) {
     // System.out.print(data[i]);
     // System.out.println((int)data[i]);
     if (data[i] == 13) {
     } else if (data[i] == 10) {
       lines[stra] = new String(str);
       lines[stra] = lines[stra].trim();
       stra++;
       str = new char[80];
       strc = 0;
     } else {
       str[strc] = data[i];
       strc++;
     }
   } // end of for loop
   numlines = stra - 1;
 }
Exemplo n.º 12
0
  /**
   * Reads the example file specified by the example tag of a doc member and adds it to the example
   * section of the doc
   *
   * @param doc
   * @throws IOException
   */
  void setExample(Doc doc) throws IOException {
    Tag[] exampleTag = doc.tags("@example");
    if (exampleTag.length > 0) {
      StringBuffer exampleBuffer = new StringBuffer();
      FileReader in;
      int c;
      String[] pathComponents = exampleTag[0].text().split("/");
      String filePath =
          exampleTag[0].text() + "/" + pathComponents[pathComponents.length - 1] + ".pde";
      in = new FileReader(new File(exampleFolder, filePath));

      while ((c = in.read()) != -1) {
        if ((char) c == '<') {
          exampleBuffer.append("&lt;");
        } else {
          exampleBuffer.append((char) c);
        }
      }

      in.close();

      String exampleString = exampleBuffer.toString();

      EXAMPLE_TAG.setContent(exampleString);

    } else {
      EXAMPLE_TAG.setContent("None available");
    }
  }
Exemplo n.º 13
0
 public static String getContent(File file) {
   char[] b = new char[1024];
   StringBuilder sb = new StringBuilder();
   try {
     FileReader reader = new FileReader(file);
     int n = reader.read(b);
     while (n > 0) {
       sb.append(b, 0, n);
       n = reader.read(b);
     }
     reader.close();
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   return sb.toString();
 }
  /**
   * Obtener la frecuencia de una palabra.
   *
   * @param ath
   * @return
   */
  @Override
  public long getNumberWord(String path, String word) {

    int caracter;
    int numero = 0;
    String posicion = "";

    try (FileReader fr = new FileReader(path)) {

      while ((caracter = fr.read()) != -1) {

        if (caracter != ' ' && caracter != '\n' && Character.isAlphabetic(caracter)) {
          String i = String.valueOf((char) caracter);
          posicion = posicion.concat(i);

        } else {
          if (posicion.equals(word)) numero++;
          posicion = "";
        }
      }
    } catch (IOException e) {

    }

    return numero;
  }
  /**
   * Crear un nuevo fichero “DIPTONGO.TXT” con todas las palabras que contengan al menos un
   * diptongo.
   *
   * @param pathIn
   * @param pathOut
   */
  @Override
  public void writeDiptongo(String pathIn, String pathOut) {
    // TODO Auto-generated method stub

    FileWriter fw = null;
    PrintWriter pw = null;
    int letra;
    String cadena = "";
    String[] diptongos = {"ia", "ie", "io", "ua", "ue", "uo", "ai", "au", "ei", "eu", "oi", "ou"};

    try (FileReader fr = new FileReader(pathIn)) {
      fw = new FileWriter(pathOut);
      pw = new PrintWriter(fw);
      while ((letra = fr.read()) != -1) {

        if (letra != ' ' && letra != '\n' && Character.isAlphabetic(letra)) {
          String cad = String.valueOf((char) letra);
          cadena = cadena.concat(cad);
        } else {
          for (int i = 0; i < diptongos.length; i++) {
            if (cadena.contains(diptongos[i])) pw.println(cadena);
          }

          cadena = "";
        }
      }
    } catch (IOException e) {

    }
  }
  /**
   * Contar el número de palabras
   *
   * @param path
   * @return
   */
  @Override
  public long countWords(String path) {
    // Leer el fichero de path caracter a caracter

    StringBuilder palabra = new StringBuilder();
    int caracter;
    int wordNumber = 0;
    try (FileReader fr = new FileReader(path)) {
      while ((caracter = fr.read()) != -1) {
        if (Character.isAlphabetic(caracter)) {
          // leo un caracter que pertenece a una palabra
          palabra.append((char) caracter);
        }
        // termino de leer la palabra
        else if (palabra.length() > 0) {
          ++wordNumber;
          palabra = new StringBuilder();
        }
      }

    } catch (FileNotFoundException e) {
      System.err.println("File not found");
    } catch (IOException e) {
      System.err.println("IOException");
    }

    return wordNumber;
  }
  /**
   * Obtener la palabra más larga y en otro método su posición (número de orden en la secuencia de
   * palabras). Si hay más de una se toma la primera. Nota: El número de orden o posición de la
   * palabra en el texto es el lugar que ocupa, una vez contadas todas.
   *
   * @param path
   * @return
   */
  @Override
  public String longestWords(String path) {
    StringBuilder palabra = new StringBuilder();
    int caracter;
    String longestWord = "";
    try (FileReader fr = new FileReader(path)) {
      while ((caracter = fr.read()) != -1) {
        if (Character.isAlphabetic(caracter)) {
          palabra.append((char) caracter);
        } else if (palabra.length() > 0) {
          if (longestWord.length() < palabra.toString().length()) {
            longestWord = palabra.toString();
          }

          palabra = new StringBuilder();
        }
      }

    } catch (FileNotFoundException e) {
      System.err.println("File not found");
    } catch (IOException e) {
      System.err.println("IOException");
    }

    return longestWord;
  }
Exemplo n.º 18
0
 /* returns true if USB is in accessory mode */
 private boolean initFunctions(File dir, boolean useEnableFiles, char[] buffer) {
   boolean inAccessoryMode = false;
   try {
     File[] files = dir.listFiles();
     for (int i = 0; i < files.length; i++) {
       File file = useEnableFiles ? new File(files[i], "enable") : files[i];
       FileReader reader = new FileReader(file);
       int len = reader.read(buffer, 0, 1024);
       reader.close();
       int value = Integer.valueOf((new String(buffer, 0, len)).trim());
       String functionName = files[i].getName();
       if (value == 1) {
         mEnabledFunctions.add(functionName);
         if (UsbManager.USB_FUNCTION_ACCESSORY.equals(functionName)) {
           // The USB accessory driver is on by default, but it might have been
           // enabled before the USB service has initialized.
           inAccessoryMode = true;
         } else if (!UsbManager.USB_FUNCTION_ADB.equals(functionName)) {
           // adb is enabled/disabled automatically by the adbd daemon,
           // so don't treat it as a default function.
           mDefaultFunctions.add(functionName);
         }
       } else {
         mDisabledFunctions.add(functionName);
       }
     }
   } catch (Exception e) {
     Slog.e(TAG, "", e);
   }
   return inAccessoryMode;
 }
Exemplo n.º 19
0
 private void updateFunctions(File dir, boolean useEnableFiles) {
   try {
     char[] buffer = new char[1024];
     File[] files = dir.listFiles();
     for (int i = 0; i < files.length; i++) {
       File file = useEnableFiles ? new File(files[i], "enable") : files[i];
       FileReader reader = new FileReader(file);
       int len = reader.read(buffer, 0, 1024);
       reader.close();
       try {
         int value =
             Integer.valueOf((new String(buffer, 0, len)).trim()) == 1
                 ? MSG_FUNCTION_ENABLED
                 : MSG_FUNCTION_DISABLED;
         String functionName = files[i].getName();
         Message msg = Message.obtain(mHandler, value);
         msg.obj = functionName;
         mHandler.sendMessage(msg);
       } catch (NumberFormatException nfe) {
         Slog.d(TAG, files[i].getName() + " contains non-numeric data");
       }
     }
   } catch (Exception e) {
     Slog.e(TAG, "", e);
   }
 }
Exemplo n.º 20
0
    private void openFile() {
      FileReader fileReader = null;
      StringBuffer stringBuffer = new StringBuffer();
      try {
        fileReader = new FileReader(file);
        int content = 0;
        while ((content = fileReader.read()) != -1) {
          String str = String.valueOf((char) content);
          stringBuffer.append(content);
        }

      } catch (FileNotFoundException e) {
        // TODO 自动生成 catch 块
        e.printStackTrace();
      } catch (IOException e) {
        // TODO 自动生成 catch 块
        e.printStackTrace();
      } finally {
        if (fileReader != null) {
          try {
            fileReader.close();
          } catch (IOException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
          }
        }
      }
      // ~
      textArea.setText(stringBuffer.toString());
    }
Exemplo n.º 21
0
  /**
   * create new a agent service configuration from the file conf.cnf
   *
   * @throws AgentServiceException
   */
  private static void getConf() throws AgentServiceException {
    // read the json string that contain the properties from the file
    File confFile = new File("conf.cnf");
    FileReader fr;

    try {
      fr = new FileReader(confFile);
    } catch (FileNotFoundException e) {
      throw new AgentServiceException("cound not file the configuration file - conf.cnf", e);
    }

    char[] buffer = new char[(int) confFile.length()];

    try {
      fr.read(buffer);
    } catch (IOException e) {
      throw new AgentServiceException("problem to read from the configuration file", e);
    } finally {
      try {
        fr.close();
      } catch (IOException e) {
      }
    }

    String jsonConfStr = new String(buffer);

    // and use the json conf contractor
    conf = AgentServiceConf.IntallConf(jsonConfStr);
  }
Exemplo n.º 22
0
  /// encode the file according to the cipher key
  // INPUT: file - the file to be encoded
  // this implementation automatocaly creates a new file with the prefix _ENCODED
  // in the same directory as the starting file
  public File encode(File sourcefile) throws IOException {

    FileReader inputStream = null;
    FileWriter outputStream = null;
    File encodedFile = new File("ENCODED_" + sourcefile.getName());
    if (!encodedFile.exists()) encodedFile.createNewFile();

    try {
      inputStream = new FileReader(sourcefile);
      outputStream = new FileWriter(encodedFile);

      int c;
      while ((c = inputStream.read()) != -1) {
        // outputStream.write(c);
        outputStream.write(encodeCharNum(c));
      }

    } finally {
      if (inputStream != null) {
        inputStream.close();
      }
      if (outputStream != null) {
        outputStream.close();
      }
    }

    return encodedFile;
  }
Exemplo n.º 23
0
  private static void getIPS() throws IOException {
    String result = "";
    String filePath = "F:\\Proxys\\";
    char[] str = new char[100000];

    // 匹配 xxx.xxx.xxx.xxx yyyy的正则表达式

    Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+\\.\\d+\\s\\d+");

    for (int i = 1; i <= 34; ++i) {
      String fileName = "proxy" + Integer.toString(i) + ".txt";
      File file = new File(filePath, fileName);
      FileReader fr = new FileReader(file);
      int j = 0;
      String tempStr;
      while (fr.read(str) != -1) {
        // System.out.println("ttt");
        //	System.out.println(str);
      }
      tempStr = String.valueOf(str);
      Matcher matcher = pattern.matcher(tempStr);
      int step = 0;
      while (matcher.find(step)) {
        result += matcher.group() + "\r\n";
        step = matcher.end();
      }
    }
    writeFile(filePath, "ProxyIp.txt", result);
  }
Exemplo n.º 24
0
  /** Returns a List of names of the tools that have been used to generate the given file. */
  public static List getToolNames(String fileName) {
    char[] buf = new char[256];
    java.io.FileReader stream = null;
    int read, total = 0;

    try {
      stream = new java.io.FileReader(fileName);

      for (; ; )
        if ((read = stream.read(buf, total, buf.length - total)) != -1) {
          if ((total += read) == buf.length) break;
        } else break;

      return makeToolNameList(new String(buf, 0, total));
    } catch (java.io.FileNotFoundException e1) {
    } catch (java.io.IOException e2) {
      if (total > 0) return makeToolNameList(new String(buf, 0, total));
    } finally {
      if (stream != null)
        try {
          stream.close();
        } catch (Exception e3) {
        }
    }

    return new ArrayList();
  }
Exemplo n.º 25
0
  public static String fileToString(final File src, final int readBufferSize)
      throws FileNotFoundException, IOException {
    final FileReader in = new FileReader(src);

    final long length = src.length();
    if (length > 1024 * 1024 * 1024) {
      throw new IllegalArgumentException();
    }

    final char[] readBuffer = new char[readBufferSize];

    final StringBuilder result = new StringBuilder((int) length);
    try {
      while (true) {
        final int numRead = in.read(readBuffer, 0, readBufferSize);
        if (numRead < 0) {
          break;
        }

        result.append(readBuffer, 0, numRead);
      }
    } finally {
      in.close();
    }

    return (result.toString());
  }
  public static void main(String[] args) {
    Scanner lea = new Scanner(System.in);

    System.out.println("Direccion?: ");
    String path = lea.nextLine();
    File f = new File(path);

    try (FileReader fr = new FileReader(f)) {
      char buffer[] = new char[(int) f.length()];
      int bytes = fr.read(buffer);
      System.out.println("Contenido:\n-----------------");
      System.out.println(buffer);
      System.out.println("Bytes leidos: " + bytes);
      // fr.skip(10);
      // otra vez!---
      System.out.println("\nAhora con Scaner\n-------------");
      Scanner lector = new Scanner(f);
      while (lector.hasNext()) {
        System.out.println(lector.nextLine());
      }

    } catch (IOException e) {
      System.out.println(e);
    }
  }
Exemplo n.º 27
0
  public static void readAndWrite(File fIn, File fOut) {
    FileReader fileReader = null;
    FileWriter fileWriter = null;

    try {
      fileReader = new FileReader(fIn);
      fileWriter = new FileWriter(fOut);
      char[] temp = new char[1024];
      while ((fileReader.read(temp)) != -1) {
        fileWriter.write(temp);
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (fileReader != null)
        try {
          fileReader.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (fileWriter != null) {
        try {
          fileWriter.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
  private static void agregaHashEquipasTenis(File ficheiro_global, String hashequipas_tenis)
      throws IOException {
    // TODO Auto-generated method stub
    String s_final = null;
    FileReader fr = new FileReader(ficheiro_global);
    char[] creader = new char[(int) ficheiro_global.length()];
    fr.read(creader);
    s_final = new String(creader);
    Pattern pattern = Pattern.compile(hashequipas_tenis);
    Matcher matcher = pattern.matcher(s_final);

    boolean enc_padrao = false;

    // vector com as ocorrências dos padrões das hashtags de equipas de ténis
    Vector<String> vec_string = new Vector<String>();

    while (matcher.find()) {
      //			System.out.println("I found the text: " + matcher.group());
      //			System.out.println("Inicial index: " + matcher.start());
      //			System.out.println("Inicial index: " + matcher.end());
      vec_string.add(matcher.group());
      enc_padrao = true;
    }

    // se existem padrões relativos a ténis ele gere (insere e remove) as hashtags associadas a
    // essas equipas
    if (enc_padrao) VerificaHashEquipasAppM.recolheDadosHashEquipa(vec_string);

    // caso contrário confirma que não ficaram na bd hashtags de equipas que o utilizador já não
    // quer ver
    else HashEquipa.eliminaHashEquipaMod("Ténis");
  }
  /**
   * Crear fichero “PALMINUS.TXT”, con todas las palabras que empiezan por letra mayúscula y
   * minúscula, respectivamente (cada palabra en una línea).
   *
   * @param pathIn
   * @param pathOut
   */
  @Override
  public void writeLowerCase(String pathIn, String pathOut) {
    // TODO Auto-generated method stub
    int caracter;
    String cadena = "";
    try (FileReader fr = new FileReader(pathIn)) {
      FileWriter fichero = new FileWriter(pathOut);
      PrintWriter pw = new PrintWriter(fichero);

      // mientras el caracter lo lea

      while ((caracter = fr.read()) != -1) {

        if (caracter != ' ' && caracter != '\n' && Character.isAlphabetic(caracter)) {
          String i = String.valueOf((char) caracter);
          cadena = cadena.concat(i);

        } else {
          if (!cadena.matches("[A-Z]+[a-z]*")) // sólo letras A a la Z
          pw.println(cadena);
          cadena = "";
        }
      }
    } catch (IOException e) {

    }
  }
Exemplo n.º 30
0
  public static int ejercicio10(String nombrefichero) {

    File fichero = new File(nombrefichero);
    FileReader fr = null;
    int contar = 0;

    // Declaramos el fichero
    try {
      fr = new FileReader(fichero); // Creamos el flujo de entrada
      int i;

      while ((i = fr.read()) != -1) {
        // se va leyendo un caracter
        if (esCaracter((char) i)) ++contar;

        // System.out.print((char) i);

      }
      fr.close(); // cerramos el fichero
    } catch (FileNotFoundException fnfe) {
      System.out.println("El fichero " + nombrefichero + " no se encuentra");
    } catch (IOException ioe) {
      System.out.println("El disco está lleno o protegido contra escritura ");
    }
    return contar;
  }