Create a new ODS file writer from a document. Be careful: this method opens immediatly a
stream.

@param filename the name of the destination file
@return the ods writer
@throws FileNotFoundException if the file can't be found
487514
public NamedOdsFileWriter createWriter(final String filename) throws IOException {
        final NamedOdsDocument document = this.createNamedDocument();
        final NamedOdsFileWriter writer = OdsFileDirectWriter.builder(this.logger, document)
                .openResult(this.openFile(filename)).build();
        document.addObserver(writer);
        document.prepareFlush();
        return writer;
    }
1312905
public boolean add(String fileName) {
      writeLock.lock();
      try {
         return filenames.add(fileName);
      } finally {
         writeLock.unlock();
      }
   }
541576
def write(self, filename, header=None):
        

        origfile = self._filename

        try:
            with open(filename, 'w') as _file:
                self.writestream(_file, header)
                self._filename = filename
            return True

        except IOError:
            self._filename = origfile
            return False
533934
public void generate(final File fileName) {
        final File outputFile = removeTemplatePrefix(fileName);
        templateFile = fileName;

        try (final InputStream in = new BufferedInputStream(new FileInputStream(fileName));
             final OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile))) {
            final Transformer transformer = TransformerFactory.newInstance().newTransformer();
            final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
            parserFactory.setNamespaceAware(true);
            XMLReader reader = parserFactory.newSAXParser().getXMLReader();
            this.setContentHandler(null);
            this.setParent(reader);
            reader = this;
            final Source source = new SAXSource(reader, new InputSource(in));
            source.setSystemId(fileName.toURI().toString());
            final Result result = new StreamResult(out);
            transformer.transform(source, result);
        } catch (final RuntimeException e) {
            throw e;
        } catch (final Exception e) {
            logger.error("Failed to transform " + fileName + ": " + e.getMessage(), e);
        }
    }
645154
public static void writeReadDeleteDocument(DatabaseClient client, String filename, String format) throws IOException {
    // create a manager for documents of any format
    GenericDocumentManager docMgr = client.newDocumentManager();

    InputStream docStream = Util.openStream("data"+File.separator+filename);
    if (docStream == null)
      throw new IOException("Could not read document example");

    // create an identifier for the document
    String docId = "/example/"+filename;

    // create a handle for the document
    InputStreamHandle writeHandle = new InputStreamHandle();
    writeHandle.set(docStream);

    // write the document
    docMgr.write(docId, writeHandle);

    // create a handle to receive the document content
    BytesHandle readHandle = new BytesHandle();

    // read the document content
    docMgr.read(docId, readHandle);

    // access the document content
    byte[] document = readHandle.get();

    // ... do something with the document content ...

    // delete the document
    docMgr.delete(docId);

    System.out.println("Wrote, read, and deleted /example/"+filename+
      " content with "+document.length+" bytes in the "+format+" format");
  }
877699
public static Document resourceFileToXMLDocument(final String location, final String fileName) {
        if (location == null || fileName == null) return null;

        final InputStream in = ResourceUtilities.class.getResourceAsStream(location + fileName);
        if (in == null) return null;

        final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder dBuilder;
        Document doc = null;
        try {
            dBuilder = dbFactory.newDocumentBuilder();
            doc = dBuilder.parse(in);
        } catch (Exception e) {
            LOG.error("Failed to parse the resource as XML.", e);
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                LOG.error("Failed to close the InputStream", e);
            }
        }
        return doc;
    }
1155281
@Nonnull
  @SuppressFBWarnings ("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
  @MustBeLocked (ELockType.WRITE)
  private ESuccess _writeToFile ()
  {
    // Build the filename to write to
    final String sFilename = m_aFilenameProvider.get ();
    if (sFilename == null)
    {
      // We're not operating on a file! Required for testing
      if (!isSilentMode ())
        if (LOGGER.isWarnEnabled ())
          LOGGER.warn ("The DAO of class " + getClass ().getName () + " cannot write to a file");
      return ESuccess.FAILURE;
    }

    // Check for a filename change before writing
    if (!sFilename.equals (m_sPreviousFilename))
    {
      onFilenameChange (m_sPreviousFilename, sFilename);
      m_sPreviousFilename = sFilename;
    }

    if (isDebugLogging ())
      if (LOGGER.isInfoEnabled ())
        LOGGER.info ("Trying to write DAO file '" + sFilename + "'");

    File aFile = null;
    IMicroDocument aDoc = null;
    try
    {
      // Get the file handle
      aFile = getSafeFile (sFilename, EMode.WRITE);

      m_aStatsCounterWriteTotal.increment ();
      final StopWatch aSW = StopWatch.createdStarted ();

      // Create XML document to write
      aDoc = createWriteData ();
      if (aDoc == null)
        throw new DAOException ("Failed to create data to write to file");

      // Generic modification
      modifyWriteData (aDoc);

      // Perform optional stuff like backup etc. Must be done BEFORE the output
      // stream is opened!
      beforeWriteToFile (sFilename, aFile);

      // Get the output stream
      final OutputStream aOS = FileHelper.getOutputStream (aFile);
      if (aOS == null)
      {
        // Happens, when another application has the file open!
        // Logger warning already emitted
        throw new DAOException ("Failed to open output stream");
      }

      // Write to file (closes the OS)
      final IXMLWriterSettings aXWS = getXMLWriterSettings ();
      if (MicroWriter.writeToStream (aDoc, aOS, aXWS).isFailure ())
        throw new DAOException ("Failed to write DAO XML data to file");

      m_aStatsCounterWriteTimer.addTime (aSW.stopAndGetMillis ());
      m_aStatsCounterWriteSuccess.increment ();
      m_nWriteCount++;
      m_aLastWriteDT = PDTFactory.getCurrentLocalDateTime ();
      return ESuccess.SUCCESS;
    }
    catch (final Exception ex)
    {
      final String sErrorFilename = aFile != null ? aFile.getAbsolutePath () : sFilename;

      if (LOGGER.isErrorEnabled ())
        LOGGER.error ("The DAO of class " +
                      getClass ().getName () +
                      " failed to write the DAO data to '" +
                      sErrorFilename +
                      "'",
                      ex);

      triggerExceptionHandlersWrite (ex, sErrorFilename, aDoc);
      m_aStatsCounterWriteExceptions.increment ();
      return ESuccess.FAILURE;
    }
  }
1063525
public static Object xmlToObject(String fileName) throws FileNotFoundException {
		FileInputStream fi = new FileInputStream(fileName);
		XMLDecoder decoder = new XMLDecoder(fi);
		Object object = decoder.readObject();
		decoder.close();
		return object;
	}
294240
def create_file(self, fileName, contents=""):
        
        with open(fileName, "w") as written_file:
            written_file.write(contents)
200216
public static File toFile(final String filename) {
        if (filename == null) {
            return null;
        }
        String f;
        try {
            f = URLDecoder.decode(filename, UTF8);
        } catch (final UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        f = f.replace(WINDOWS_SEPARATOR, File.separator).replace(UNIX_SEPARATOR, File.separator);
        return new File(f);
    }
1240494
public static String readFileContent(String filename) throws FileNotFoundException, IOException {
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        StringBuilder content = new StringBuilder();
        String line;
        final String eol = System.getProperty("line.separator");
        while ((line = reader.readLine()) != null) {
            content.append(line);
            content.append(eol);
        }
        reader.close();
        return content.toString();
    }
141568
public Document readDocumentFromFile(String filename) {

            ProvFormat format = getTypeForFile(filename);
            if (format == null) {
                throw new InteropException("Unknown output file format: "
                        + filename);
            }
            return readDocumentFromFile(filename, format);
    }
259199
public static OutputStream toFile(String filepath) throws FileNotFoundException {
		if(Strings.isValid(filepath)) {
			return new FileOutputStream(new File(filepath));
		}
		return null;
	}
1318251
public static FileCreationState newFile(final File file) throws IOException
	{
		FileCreationState fileCreationState = FileCreationState.ALREADY_EXISTS;
		if (!file.exists())
		{
			fileCreationState = FileCreationState.FAILED;
			newParentDirectories(file);
			if (file.createNewFile())
			{
				fileCreationState = FileCreationState.CREATED;
			}
		}
		return fileCreationState;
	}
1285093
public static InputStream loadFile(String fileName) {
        logger.entering(fileName);
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        InputStream iStream = loader.getResourceAsStream(fileName);
        if (iStream == null) {
            try {
                iStream = new FileInputStream(fileName);
            } catch (FileNotFoundException e) { // NOSONAR
                // Gobbling the checked exception here and doing nothing with it
                // because we are explicitly checking if the inputstream is null
                // and then throwing a runtime exception
            }
        }
        if (iStream == null) {
            throw new IllegalArgumentException("[" + fileName + "] is not a valid resource");
        }
        logger.exiting();
        return iStream;
    }
1275370
public static XWPFDocument create(File file) {
		try {
			return FileUtil.exist(file) ? new XWPFDocument(OPCPackage.open(file)) : new XWPFDocument();
		} catch (InvalidFormatException e) {
			throw new POIException(e);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
1356518
public void writeToFileWithoutFactors(String filename) throws IOException {
        FileOutputStream fos = new FileOutputStream(filename);
        writeToStreamWithoutFactors(fos);
        fos.close();
    }