Discutez d'informatique ici !
Morpheus
Membre Naturel
Messages: 36
Enregistré le: 02 Fév 2006, 18:38

[Résolu] Lecture et écriture dans un fichier

par Morpheus » 07 Juin 2006, 17:43

Bonjour,

je voudrais savoir comment faire pour lire un fichier et écrire dans un autre les lignes lues en majuscule.

Merci



Morpheus
Membre Naturel
Messages: 36
Enregistré le: 02 Fév 2006, 18:38

par Morpheus » 07 Juin 2006, 17:44

Voici les différentes interfaces qui sont fournis avec l'énoncé
Code: Tout sélectionner
import java.util.Collection;

/** Represents a context strategy i.e. how to obtain a context
 *  of the indexed words.
 * 
 *
 * @see FoogleFacade#getAllContextStrategies()
 * @see FoogleFacade#createIndex(ContextStrategy)
 */
public interface ContextStrategy {
  /** Retruns the name of the Strategy.
   * @return the name of the current strategy.
   */
  public String getName();
 
  /** Returns the context of a result,
   *  this result must be created by a query on an
   *  index that use the current strategy.
   *
   * @param result of a qery on an index that
   *  used this strategy.
   * @return an unmodifiable list of words representing
   *  the context of the result.
   * 
   * @throws IllegalArgumentException if the result is not created
   *  with an index using this strategy.
   * 
   *@see Index#getContextStrategy()
   */
  public Collection getContext(Result result);
}





import java.io.File;
import java.io.IOException;
import java.io.Reader;

import java.util.Map;
import java.util.regex.Pattern;

/** Access point for creating, loading, saving foogle index and
 *  performs some queries on it.
 *
 */
public interface FoogleFacade {
  /** Creates an in-memory index with a specified strategy
   *  and appends all words extracted of a specific file.
   * @param strategy the context strategy used to create the index.
   * @param file all words of the file will be appended in the index.
   * @return a new in-memory index.
   * @throws IOException if the file doesn't exists or is unreadable.
   */
  public Index createIndex(File file,ContextStrategy strategy) throws IOException;
 
  /** Creates an in-memory index with a specified strategy
   *  and appends all words extracted of a specific file.
   *  All words are appended with the line of the reader and the specifed filename.
   * 
   *  Words are separated using the java whitespace rule
   *  \p{javaWhitespace} (see {@link Pattern})
   *  and word are indexed is its length is greater or equals to 3.
   * 
   * @param strategy the context strategy used to create the index.
   * @param filename filename used for all word from the reader.
   * @param reader all words contained in the reader will be appended line by line
   *  in the index.
   * @return a new in-memory index.
   * @throws IOException if the file doesn't exists or is unreadable.
   *
   */
  public Index createIndex(String filename,Reader reader,ContextStrategy strategy) throws IOException;
 
  /** Creates an in-memory index with a specified strategy
   *  and appends all words extracted of a specific file in the specified index.
   *  All words are appended with the line of the reader and the specifed filename.
   * @param strategy the context strategy used to create the index.
   * @param filename filename used for all word from the reader.
   * @param reader all words contained in the reader will be appended line by line
   *        in the index.
   * @param accepter specifies how to separate word in the reader and
   *        which words are indexable.
   * @return a new in-memory index.
   * @throws IOException if the file doesn't exists or is unreadable.
   *
   * @see
   */
  public Index createIndex(String filename,Reader reader,WordAccepter accepter,ContextStrategy strategy) throws IOException;

 
  /** Loads an index stored in a file in memory.
   * @param indexFile file that store the index.
   * @return an in-memory index corresponding to the file.
   * @throws IOException raised if there is input/output problems.
   */
  public Index loadIndex(File indexFile)  throws IOException;
 
  /** Saves an index in a spacific file.
   * @param index the index to store.
   * @param indexFile file that will store the index.
   * @throws IOException raised if there is input/output problems.
   */
  public void saveIndex(Index index,File indexFile) throws IOException;
 
  /** Returns a query factory specific to an index.
   * @param index the queries will be created on this index.
   * @return a new query factory.
   *
   * @see Query#execute(int)
   */
  public QueryFactory createQueryFactory(Index index);
 
  /** Returns all context strategies understood by the facade.
   *  This method must returned at least the "none" context strategy.
   * @return an unmodifiable map of context strategies associated
   *  with their names.
   */
  public Map getContextStrategyMap(); 
}






/** Represents an index of Foogle.
 *
 *
 */
public interface Index {
  /** Returns the name of the indexed file.
   * @return the name of the indexed file.
   */
  public String getFilename();
 
  /** Returns the context startegy used by the current index.
   * @return the context strategy.
   *
   * @see FoogleFacade#createIndex(ContextStrategy)
   * @see FoogleFacade#getAllContextStrategies()
   */
  public ContextStrategy getContextStrategy();
}









/** Represents a query to an index.
 *  The query is specific to an index.
 * 
 *
 * @see QueryFactory
 * @see FoogleFacade#createQueryFactory(Index)
 */
public interface Query {
  /** Query the index to find results corresponding to a
   *  specific query.
   *
   * @return the result of the query.
   *
   * @see Query#execute(int)
   */
  public Iterable execute();
 
  /** Query the index to find results corresponding to a
   *  specific query.
   * 
   *  @param maxCount a positive integer
   *
   * @return the result of the query.
   *
   * @see QueryFactory
   * @see FoogleFacade#createQueryBuilder(String)
   */
  public Iterable execute(int maxCount);
}






import java.util.regex.Pattern;

/** Factory used to create index queries,
 *  The factory is specific to an index.
 * 
 *  All results returned by {@link Query#execute()}
 *  on these queries are garanteed to have distinct
 *  line numbers (see {@link Result#getLine()}).
 *
 */
public interface QueryFactory {
  /** Creates a query for a simple word.
   *
   * @param word the queried word.
   * @return a new query.
   */
  public Query query(CharSequence word);
 
  /** Creates a query for a regex.
   *
   * @param pattern the queried regex.
   * @return a new query.
   */
  public Query query(Pattern pattern);
 
  /** Create a new query by oring query1 and query2.
   * 
   * @param query1 the first query.
   * @param query2 the second query.
   * @return the new query.
   */
  public Query or(Query query1,Query query2);
 
  /** Create a new query by anding query1 and query2.
   * @param query1 the first query.
   * @param query2 the second query.
   * @return the new query.
   */
  public Query and(Query query1,Query query2);
}







/** Result of a query, represents a location in a line of a file.
 *
 *  A result can have a specific context value associated with it
 *  depending on the index strategy, use
 *  {@link ContextStrategy#getContext(Result)} to obtain such context.
 *
 *
 * @see Index#executeQuery(Query)
 */
public interface Result {
  /** Returns the line number containing
   *  the result
   * @return a line number.
   */
  public int getLine();
}







import java.util.Scanner;
import java.util.regex.Pattern;

/** This interface specifies
 *  how words are delimited in a text
 *  using a regex pattern
 *  {@link #getDelimiterRegex()}
 *  and which word are indexed
 *  {@link #isIndexable(CharSequence)}.
 *
 */
public interface WordAccepter {
  /** Returns the regex pattern used to separate words.
   * @return a regex pattern.
   *
   * @see Scanner#useDelimiter(Pattern)
   */
  public Pattern getDelimiterRegex();
 
  /** Indicates if a word should be indexed or not.
   * @param word the word
   * @return true if the word is indexable, false otherwise.
   */
  public boolean isIndexable(CharSequence word);
}

Retourner vers ϟ Informatique

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité

Tu pars déja ?



Fais toi aider gratuitement sur Maths-forum !

Créé un compte en 1 minute et pose ta question dans le forum ;-)
Inscription gratuite

Identification

Pas encore inscrit ?

Ou identifiez-vous :

Inscription gratuite