java类java.io.FileWriter的实例源码

RenameUserTest.java 文件源码 项目:alfresco-repository 阅读 20 收藏 0 点赞 0 评论 0
private void createFile(String content) throws Exception
{
    file = File.createTempFile("RenameUserTest", ".txt");
    args[4] = "-file";
    args[5] = file.getPath();

    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write(content);
    out.close();
}
MeterVirialBDBin.java 文件源码 项目:etomica 阅读 19 收藏 0 点赞 0 评论 0
public void writeData(String filename) {
    try {
        FileWriter fw = new FileWriter(filename);
        fw.write(""+totalCount+"\n");
        for (int i=0; i<unscreenedCount.length; i++) {
            long sampleCount = accumulators[i].getSampleCount();
            if (sampleCount == 0) continue;
            long usc = unscreenedCount[i];
            AllData ad = accumulators[i].getRawData();
            fw.write(i+" "+usc+" "+ad.count+" "+((DataDoubleBDArray)ad.sum).getData()[0].toString()+" "+((DataDoubleBDArray)ad.sumSquare).getData()[0].toString()+"\n");
        }
        fw.close();
    }
    catch (IOException e) {
        throw new RuntimeException(e);
    }
}
TestConfiguration.java 文件源码 项目:hadoop 阅读 34 收藏 0 点赞 0 评论 0
public void testFloatValues() throws IOException {
  out=new BufferedWriter(new FileWriter(CONFIG));
  startConfig();
  appendProperty("test.float1", "3.1415");
  appendProperty("test.float2", "003.1415");
  appendProperty("test.float3", "-3.1415");
  appendProperty("test.float4", " -3.1415 ");
  appendProperty("test.float5", "xyz-3.1415xyz");
  endConfig();
  Path fileResource = new Path(CONFIG);
  conf.addResource(fileResource);
  assertEquals(3.1415f, conf.getFloat("test.float1", 0.0f));
  assertEquals(3.1415f, conf.getFloat("test.float2", 0.0f));
  assertEquals(-3.1415f, conf.getFloat("test.float3", 0.0f));
  assertEquals(-3.1415f, conf.getFloat("test.float4", 0.0f));
  try {
    conf.getFloat("test.float5", 0.0f);
    fail("Property had invalid float value, but was read successfully.");
  } catch (NumberFormatException e) {
    // pass
  }
}
LocalSignatureKeyContainerTest.java 文件源码 项目:PACE 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void writeReadTest() throws Exception {
  for (ValueSigner signer : ValueSigner.values()) {
    KeyPairGenerator gen = KeyPairGenerator.getInstance(signer.getKeyGenerationAlgorithm());
    if (signer == ValueSigner.ECDSA) {
      gen.initialize(256);
    } else {
      gen.initialize(1024);
    }

    KeyPair pair = gen.generateKeyPair();
    byte[] keyId = String.format("%s_%s", gen.getAlgorithm(), "test").getBytes(ENCODING_CHARSET);
    LocalSignatureKeyContainer container = new LocalSignatureKeyContainer(pair, keyId);

    File file = folder.newFile();
    FileWriter writer = new FileWriter(file);
    container.write(writer);
    writer.close();

    LocalSignatureKeyContainer container2 = LocalSignatureKeyContainer.read(new FileReader(file));
    assertThat("has matching keys", container2.getSigningKey().key.getEncoded(), equalTo(container.getSigningKey().key.getEncoded()));
    assertThat("has matching keys", container2.getSigningKey().id, equalTo(container.getSigningKey().id));
    assertThat("has matching keys", container2.getVerifyingKey(keyId).getEncoded(), equalTo(container.getVerifyingKey(keyId).getEncoded()));
  }

}
OracleCallExportTest.java 文件源码 项目:aliyun-maxcompute-data-collectors 阅读 18 收藏 0 点赞 0 评论 0
public void testExportUsingProcedure() throws IOException, SQLException {
  String[] lines = {
    "0,textfield0,2002-12-29 08:40:00,3300",
    "1,textfield1,2007-06-04 13:15:10,4400",
  };
  new File(getWarehouseDir()).mkdirs();
  File file = new File(getWarehouseDir() + "/part-00000");
  Writer output = new BufferedWriter(new FileWriter(file));
  for (String line : lines) {
    output.write(line);
    output.write("\n");
  }
  output.close();
  runExport(getArgv());
  verifyExport(2, getConnection());
}
NpmPackageToProjectAdapter.java 文件源码 项目:n4js 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Writes contents of the {@link N4MFConstants#N4MF_MANIFEST manifest file} for a given npm package.
 *
 * @param projectFolder
 *            root folder of the npm package in which manifest is written
 * @param packageJSON
 *            that will be used as manifest data source
 * @param mainModule
 *            the main module
 * @param manifest
 *            file to which contents should be written
 *
 */
private void generateManifestContent(File projectFolder, PackageJson packageJSON, String mainModule,
        File manifest)
        throws IOException {

    String projectId = packageJSON.name;
    String projectVersion = packageJSON.version;

    if (!projectFolder.getName().equals(projectId)) {
        LOGGER.warn("project folder and project name are different : " + projectFolder.getName() + " <> + "
                + packageJSON.name);
    }

    try (FileWriter fw = new FileWriter(manifest)) {
        fw.write(manifestContentProvider.getContent(projectId, ".", ".", mainModule, projectVersion));
    }
}
TestConfiguration.java 文件源码 项目:hadoop 阅读 30 收藏 0 点赞 0 评论 0
public void testPropertySource() throws IOException {
  out = new BufferedWriter(new FileWriter(CONFIG));
  startConfig();
  appendProperty("test.foo", "bar");
  endConfig();
  Path fileResource = new Path(CONFIG);
  conf.addResource(fileResource);
  conf.set("fs.defaultFS", "value");
  String [] sources = conf.getPropertySources("test.foo");
  assertEquals(1, sources.length);
  assertEquals(
      "Resource string returned for a file-loaded property" +
      " must be a proper absolute path",
      fileResource,
      new Path(sources[0]));
  assertArrayEquals("Resource string returned for a set() property must be " +
        "\"programatically\"",
      new String[]{"programatically"},
      conf.getPropertySources("fs.defaultFS"));
  assertEquals("Resource string returned for an unset property must be null",
      null, conf.getPropertySources("fs.defaultFoo"));
}
CadastroInterface.java 文件源码 项目:lembredio 阅读 20 收藏 0 点赞 0 评论 0
public void swapFile(String file1) throws FileNotFoundException, IOException{
            File file = new File(file1);
            if(!file.exists()) file.createNewFile();
            FileWriter outputfile = new FileWriter(file1, true);
            PrintWriter out = new PrintWriter(outputfile);

                out.println(vlogin.type);
                out.println(vlogin.login);
                out.println(vlogin.senha);
                out.println(plogin.nome);
                out.println(plogin.email);
                if(vlogin.type==1) out.println(medico.getCRM());
                if(vlogin.type==2) out.println(farma.getnomeFarmacia());


          out.close();
}
JsonWriting.java 文件源码 项目:Java-Data-Science-Cookbook 阅读 21 收藏 0 点赞 0 评论 0
public void writeJson(String outFileName){
    JSONObject obj = new JSONObject();
    obj.put("book", "Harry Potter and the Philosopher's Stone");
    obj.put("author", "J. K. Rowling");

    JSONArray list = new JSONArray();
    list.add("There are characters in this book that will remind us of all the people we have met. Everybody knows or knew a spoilt, overweight boy like Dudley or a bossy and interfering (yet kind-hearted) girl like Hermione");
    list.add("Hogwarts is a truly magical place, not only in the most obvious way but also in all the detail that the author has gone to describe it so vibrantly.");
    list.add("Parents need to know that this thrill-a-minute story, the first in the Harry Potter series, respects kids' intelligence and motivates them to tackle its greater length and complexity, play imaginative games, and try to solve its logic puzzles. ");

    obj.put("messages", list);

    try {

        FileWriter file = new FileWriter(outFileName);
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);
}
UMLDiagramPanel.java 文件源码 项目:onprom 阅读 28 收藏 0 点赞 0 评论 0
public void exportImage() {
  try {
    File file = IOUtility.selectFileToSave(FileType.IMAGE);
    if (file != null) {
      Rectangle drawingArea = getDrawingArea();
      String extension = FilenameUtils.getExtension(file.getName());
      if (extension.equals("svg")) {
        SVGGraphics2D svgGenerator = IOUtility.getSVGGraphics(drawingArea.getSize());
        paintDrawing(svgGenerator, drawingArea.x, drawingArea.y);
        svgGenerator.stream(new FileWriter(file));
        svgGenerator.dispose();
      } else {
        BufferedImage bi = new BufferedImage(drawingArea.width, drawingArea.height, BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.createGraphics();
        paintDrawing(g, drawingArea.x, drawingArea.y);
        ImageIO.write(bi, extension, file);
        g.dispose();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}


问题


面经


文章

微信
公众号

扫码关注公众号