Example #1
0
  private String ReadWholeFileToString(String filename) {

    File file = new File(filename);
    StringBuffer contents = new StringBuffer();
    BufferedReader reader = null;

    try {
      reader = new BufferedReader(new FileReader(file));
      String text = null;

      // repeat until all lines is read
      while ((text = reader.readLine()) != null) {
        contents.append(text).append(System.getProperty("line.separator"));
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (reader != null) {
          reader.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    // show file contents here
    return contents.toString();
  }
 public String getAlbumName() {
   if (albumName != null) {
     return albumName;
   }
   // from text file "pm_album_name.txt"
   if (homeBilder == null) {
     return "not-found";
   }
   // File Album-name nicht vorhanden
   if (albumName == null) {
     homeFileAlbumName = new File(getMetaRootDir() + File.separator + FILE_ALBUM_NAME);
     if (!homeFileAlbumName.exists()) {
       try {
         homeFileAlbumName.createNewFile();
         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(homeFileAlbumName)));
         out.println(homeBilder.getName());
         out.close();
         // read it now ...
       } catch (IOException e) {
         albumName = "cannot-create";
         return albumName;
       }
     }
     // File exist. Read it.
     try {
       BufferedReader in = new BufferedReader(new FileReader(homeFileAlbumName));
       while (true) {
         String line = in.readLine().trim();
         if (line.startsWith("#")) {
           continue;
         }
         albumName = line.trim();
         break;
       }
       in.close();
     } catch (IOException e) {
       albumName = "cannot-create";
       return albumName;
     }
   }
   return albumName;
 }