當前位置: 首頁>>代碼示例>>Java>>正文


Java FileWriter.flush方法代碼示例

本文整理匯總了Java中java.io.FileWriter.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java FileWriter.flush方法的具體用法?Java FileWriter.flush怎麽用?Java FileWriter.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.FileWriter的用法示例。


在下文中一共展示了FileWriter.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.io.FileWriter; //導入方法依賴的package包/類
public static void main(String[] args) {

    int size = 100;
    creatStr(size, size);
    createFile(size);
    createDir(size);
    createRoot();
    createContents(size, size);

    str += "\n\ncontents in Dir -> (Dir + File)\n" + "all d:Dir | not (d in d.^contents)\n"
        + "Root in Dir\n" + "(File + Dir) in Root.*contents";
    System.out.println(str);

    File tempFile = new File(
        "./../eu.modelwriter.traceability.validation.core.crocopat/files/KodKodTestFile.kodkod");

    try {
      FileWriter fileWriter = new FileWriter(tempFile);
      fileWriter.write(str);
      fileWriter.flush();
      fileWriter.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:27,代碼來源:UniverseCreateForKodKod.java

示例2: createDaoInterface

import java.io.FileWriter; //導入方法依賴的package包/類
/**
 * 創建Dao接口
 * @param c實體類
 * @param commonPackage 基礎包:如com.jeff.tianti.info
 * @param author 作者
 * @param desc 描述
 * @throws IOException
 */
public static void createDaoInterface(Class c,String commonPackage,String author) throws IOException{
	String cName = c.getName();
	String daoPath = "";
	if(author == null || author.equals("")){
		author = "Administrator";
	}
	if(commonPackage != null && !commonPackage.equals("")){
		daoPath = commonPackage.replace(".", "/");
		String fileName = System.getProperty("user.dir") + "/src/main/java/" + daoPath+"/dao"
				+ "/" + getLastChar(cName) + "Dao.java";
		File f = new File(fileName);
		FileWriter fw = new FileWriter(f);
		fw.write("package "+commonPackage+".dao"+";"+RT_2+"import "+commonPackage+".entity"+"."+getLastChar(cName)+";"+RT_1+"import com.jeff.tianti.common.dao.CommonDao;"+RT_2
				+"/**"+RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_AUTHOR_PARAMTER+ author +RT_1
				+BLANK_1+"*"+BLANK_1+ANNOTATION_DESC +getLastChar(cName)+"Dao接口"+BLANK_1+RT_1
				+BLANK_1+"*"+BLANK_1+ANNOTATION_DATE +getDate()+RT_1+BLANK_1+"*/"+RT_1
				+"public interface " +getLastChar(cName) +"Dao extends "+getLastChar(cName)+"DaoCustom,CommonDao<"+getLastChar(cName)+",String>{"+RT_2+"}");
		fw.flush();
		fw.close();
		showInfo(fileName);
	}else{
		System.out.println("創建Dao接口失敗,原因是commonPackage為空!");
	}
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:33,代碼來源:GenCodeUtil.java

示例3: logInfo

import java.io.FileWriter; //導入方法依賴的package包/類
private void logInfo(String msg) {
    if (logPath == null) {
        logger.info(msg);
    } else {
        try {
            FileUtils.createFile(logPath);
            // WTF windows
            FileWriter fw = new FileWriter(logPath, true);
            fw.write(msg);
            fw.write("\n");
            fw.flush();
            fw.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:18,代碼來源:FindNotMakeTest.java

示例4: saveFile

import java.io.FileWriter; //導入方法依賴的package包/類
public static File saveFile(Context context, String filename, String dados) {

        if (!isExternalStorageWritable())
            Toast.makeText(context, context.getString(R.string.n_001), Toast.LENGTH_LONG).show();

        if (isExternalStorageReadable()) {
            Toast.makeText(context, context.getString(R.string.n_001), Toast.LENGTH_LONG).show();
        }

        try {
            File root = new File(Environment.getExternalStorageDirectory(), context.getString(context.getApplicationInfo().labelRes));
            if (!root.exists())
                //noinspection ResultOfMethodCallIgnored
                root.mkdirs();

            File sFile = new File(root, filename);
            if (sFile.exists())
                //noinspection ResultOfMethodCallIgnored
                sFile.delete();

            FileWriter writer = new FileWriter(sFile);
            writer.append(dados);
            writer.flush();
            writer.close();

            return sFile;
        } catch (IOException e) {
            Toast.makeText(context, context.getString(R.string.n_001), Toast.LENGTH_LONG).show();
        }

        return null;
    }
 
開發者ID:marcelohanel,項目名稱:PokerBankroll,代碼行數:33,代碼來源:Funcoes.java

示例5: createDaoCustomInterface

import java.io.FileWriter; //導入方法依賴的package包/類
/**
 * 創建DaoCustom接口
 * @param c實體類
 * @param commonPackage 基礎包:如com.jeff.tianti.info
 * @throws IOException
 */
public static void createDaoCustomInterface(Class c,String commonPackage,String author) throws IOException{
	String cName = c.getName();
	String daoPath = "";
	if(author == null || author.equals("")){
		author = "Administrator";
	}
	if(commonPackage != null && !commonPackage.equals("")){
		daoPath = commonPackage.replace(".", "/");
		String fileName = System.getProperty("user.dir") + "/src/main/java/" + daoPath+"/dao"
				+ "/" + getLastChar(cName) + "DaoCustom.java";
		File f = new File(fileName);
		FileWriter fw = new FileWriter(f);
		fw.write("package "+commonPackage+".dao"+";"+RT_2
				+"import com.jeff.tianti.common.entity.PageModel;"+RT_1
				+"import java.util.List;"+RT_1
				+"import "+commonPackage+".entity"+"."+getLastChar(cName)+";"+RT_1
				+"import "+commonPackage+".dto"+"."+getLastChar(cName)+"QueryDTO;"+RT_1
				+"/**"+RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_AUTHOR_PARAMTER+ author +RT_1
				+BLANK_1+"*"+BLANK_1+ANNOTATION_DESC +getLastChar(cName)+"DaoCustom接口"+BLANK_1+RT_1
				+BLANK_1+"*"+BLANK_1+ANNOTATION_DATE +getDate()+RT_1+BLANK_1+"*/"+RT_1
				+"public interface " +getLastChar(cName) +"DaoCustom {"+RT_2
				+"      PageModel<"+getLastChar(cName)+"> query"+getLastChar(cName)+"Page("+getLastChar(cName)+"QueryDTO "+getFirstLowercase(cName)+"QueryDTO);"+RT_2
				+"      List<"+getLastChar(cName)+"> query"+getLastChar(cName)+"List("+getLastChar(cName)+"QueryDTO "+getFirstLowercase(cName)+"QueryDTO);"+RT_2
				+RT_2+"}");
		fw.flush();
		fw.close();
		showInfo(fileName);
	}else{
		System.out.println("創建DaoCustom接口失敗,原因是commonPackage為空!");
	}
	
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:39,代碼來源:GenCodeUtil.java

示例6: clearFile

import java.io.FileWriter; //導入方法依賴的package包/類
public static void clearFile(File file){
      try {
      	if(file != null && file.exists() && file.isFile()){
      		FileWriter fileWriter =new FileWriter(file);
      		fileWriter.write("");
      		fileWriter.flush();
      		fileWriter.close();        		
      	}
} catch (IOException e) {
	e.printStackTrace();
}
  }
 
開發者ID:huangjiaqian,項目名稱:wbczq,代碼行數:13,代碼來源:FileUtil.java

示例7: MainThread

import java.io.FileWriter; //導入方法依賴的package包/類
public MainThread(int clientPort, boolean preCreateDirs) throws IOException {
    super("Standalone server with clientPort:" + clientPort);
    tmpDir = ClientBase.createTmpDir();
    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=2000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");

    File dataDir = new File(tmpDir, "data");
    String dir = dataDir.toString();
    String dirLog = dataDir.toString() + "_txnlog";
    if (preCreateDirs) {
        if (!dataDir.mkdir()) {
            throw new IOException("unable to mkdir " + dataDir);
        }
        dirLog = dataDir.toString();
    }
    
    // Convert windows path to UNIX to avoid problems with "\"
    String osname = java.lang.System.getProperty("os.name");
    if (osname.toLowerCase().contains("windows")) {
        dir = dir.replace('\\', '/');
        dirLog = dirLog.replace('\\', '/');
    }
    fwriter.write("dataDir=" + dir + "\n");
    fwriter.write("dataLogDir=" + dirLog + "\n");
    fwriter.write("clientPort=" + clientPort + "\n");
    fwriter.flush();
    fwriter.close();

    main = new TestZKSMain();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:35,代碼來源:ZooKeeperServerMainTest.java

示例8: logMessage

import java.io.FileWriter; //導入方法依賴的package包/類
public static synchronized void logMessage(List<String> list) {
    synchronized (LOG.class) {
        if (!(CommonUtils.isBlank(b) || CommonUtils.isBlank(c))) {
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(c);
            for (String str : list) {
                stringBuffer.append(", " + str);
            }
            stringBuffer.append("\n");
            try {
                File file = new File(a);
                if (!file.exists()) {
                    file.mkdirs();
                }
                File file2 = new File(a, b);
                if (!file2.exists()) {
                    file2.createNewFile();
                }
                FileWriter fileWriter = file2.length() + ((long) stringBuffer.length()) <= 51200 ? new FileWriter(file2, true) : new FileWriter(file2);
                fileWriter.write(stringBuffer.toString());
                fileWriter.flush();
                fileWriter.close();
            } catch (Exception e) {
                e.toString();
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:29,代碼來源:LOG.java

示例9: save

import java.io.FileWriter; //導入方法依賴的package包/類
public void save() {
    try {
        if (file != null) {
            FileWriter writer = new FileWriter(file);
            new Gson().toJson(this, writer);
            writer.flush();
            writer.close();
        }
    } catch (IOException e) {
        Logger.logException(e);
    }
}
 
開發者ID:iTXTech,項目名稱:Daedalus,代碼行數:13,代碼來源:Configurations.java

示例10: testLocalInfileDisabled

import java.io.FileWriter; //導入方法依賴的package包/類
public void testLocalInfileDisabled() throws Exception {
    createTable("testLocalInfileDisabled", "(field1 varchar(255))");

    File infile = File.createTempFile("foo", "txt");
    infile.deleteOnExit();
    //String url = infile.toURL().toExternalForm();
    FileWriter output = new FileWriter(infile);
    output.write("Test");
    output.flush();
    output.close();

    Connection loadConn = getConnectionWithProps(new Properties());

    try {
        // have to do this after connect, otherwise it's the server that's enforcing it
        ((com.mysql.jdbc.Connection) loadConn).setAllowLoadLocalInfile(false);
        try {
            loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled");
            fail("Should've thrown an exception.");
        } catch (SQLException sqlEx) {
            assertEquals(SQLError.SQL_STATE_GENERAL_ERROR, sqlEx.getSQLState());
        }

        assertFalse(loadConn.createStatement().executeQuery("SELECT * FROM testLocalInfileDisabled").next());
    } finally {
        loadConn.close();
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:29,代碼來源:ConnectionTest.java

示例11: writeStackTrace

import java.io.FileWriter; //導入方法依賴的package包/類
public void writeStackTrace() throws IOException, InterruptedException {
    // used in window
    // File expectOutput = new File("D:\\logFolder\\expectOutput.txt");
    // FileWriter writerExpect = new FileWriter(expectOutput,true);

    // used in linux
    File expectOutput = new File("/home/work/UAV/Log/expectOutput.txt");
    @SuppressWarnings("resource")
    FileWriter writerExpect = new FileWriter(expectOutput, true);

    Thread.sleep(10000);
    logger.error("IOexception", new IOException("1111111111 failed.."));
    System.out.println(" IOexception >>>>  111111111");
    writerExpect.write(
            "{\"stacktrace\":\"java.io.IOException: 1111111111 failed..\\tat com.creditease.monitorframework.fat.Log4jTest.writeStackTrace(Log4jTest.java:191)\\tat com.creditease.monitorframework.fat.Log4jTest.doGet(Log4jTest.java:48)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:624)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:731)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:307)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)\\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)\\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)\\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)\\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)\\tat org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)\\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)\\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:443)\\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)\\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)\\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\\tat java.lang.Thread.run(Thread.java:745)\"}\r\n");
    writerExpect.flush();

    Thread.sleep(10000);
    logger.error("InterruptedException", new InterruptedException("222222222 faild.."));
    System.out.println("InterruptedException >>> 222222222");
    writerExpect.write(
            "{\"stacktrace\":\"java.lang.InterruptedException: 222222222 faild..\\tat com.creditease.monitorframework.fat.Log4jTest.writeStackTrace(Log4jTest.java:197)\\tat com.creditease.monitorframework.fat.Log4jTest.doGet(Log4jTest.java:48)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:624)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:731)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:307)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)\\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)\\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)\\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)\\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)\\tat org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)\\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)\\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:443)\\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)\\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)\\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\\tat java.lang.Thread.run(Thread.java:745)\"}\r\n");
    writerExpect.flush();

    Thread.sleep(10000);
    logger.error("ClassNotFoundException", new ClassNotFoundException("33333333"));
    System.out.println("ClassNotFoundException >>> 33333333");
    writerExpect.write(
            "{\"stacktrace\":\"java.lang.ClassNotFoundException: 33333333\\tat com.creditease.monitorframework.fat.Log4jTest.writeStackTrace(Log4jTest.java:203)\\tat com.creditease.monitorframework.fat.Log4jTest.doGet(Log4jTest.java:48)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:624)\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:731)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:307)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:212)\\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)\\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)\\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)\\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)\\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)\\tat org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)\\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)\\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:443)\\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)\\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)\\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\\tat java.lang.Thread.run(Thread.java:745)\"}\r\n");
    writerExpect.flush();

    System.out.println("*********** the end of stack trace *********");

}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:35,代碼來源:Log4jTest.java

示例12: createSimpleCSV

import java.io.FileWriter; //導入方法依賴的package包/類
public static void createSimpleCSV(GeometryImage glayer, String file,boolean append) throws IOException {
FileWriter fw = new FileWriter(file,append);
try{
       if(!append)
       	fw.append("geom," + glayer.getSchema(',') + "\n");
       WKTWriter wkt = new WKTWriter();
       for (Geometry geom : glayer.getGeometries()) {
           fw.append("\"" + wkt.writeFormatted(geom) + "\",");
           AttributesGeometry att = glayer.getAttributes(geom);
           if (att == null || att.getSchema().length==0) {
               fw.append("\n");
               continue;
           }
           for (int i = 0; i < att.getSchema().length; i++) {
               String key = att.getSchema()[i];
               fw.append(att.get(key) + "");
               if (i < att.getSchema().length - 1) {
                   fw.append(",");
               } else {
                   fw.append("\n");
               }
           }
       }
}finally{    
	fw.flush();
	fw.close();
}	
  }
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:GenericCSVIO.java

示例13: testProgressIsReportedIfInputASeriesOfEmptyFiles

import java.io.FileWriter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testProgressIsReportedIfInputASeriesOfEmptyFiles() throws IOException, InterruptedException {
  JobConf conf = new JobConf();
  Path[] paths = new Path[3];
  File[] files = new File[3];
  long[] fileLength = new long[3];

  try {
    for(int i=0;i<3;i++){
      File dir = new File(outDir.toString());
      dir.mkdir();
      files[i] = new File(dir,"testfile"+i);
      FileWriter fileWriter = new FileWriter(files[i]);
      fileWriter.flush();
      fileWriter.close();
      fileLength[i] = i;
      paths[i] = new Path(outDir+"/testfile"+i);
    }

    CombineFileSplit combineFileSplit = new CombineFileSplit(paths, fileLength);
    TaskAttemptID taskAttemptID = Mockito.mock(TaskAttemptID.class);
    TaskReporter reporter = Mockito.mock(TaskReporter.class);
    TaskAttemptContextImpl taskAttemptContext =
      new TaskAttemptContextImpl(conf, taskAttemptID,reporter);

    CombineFileRecordReader cfrr = new CombineFileRecordReader(combineFileSplit,
      taskAttemptContext, TextRecordReaderWrapper.class);

    cfrr.initialize(combineFileSplit,taskAttemptContext);

    verify(reporter).progress();
    Assert.assertFalse(cfrr.nextKeyValue());
    verify(reporter, times(3)).progress();
  } finally {
    FileUtil.fullyDelete(new File(outDir.toString()));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:39,代碼來源:TestCombineFileRecordReader.java

示例14: blowsUpIfPassWordsFileIsMalformed

import java.io.FileWriter; //導入方法依賴的package包/類
@Test
public void blowsUpIfPassWordsFileIsMalformed() throws Exception {
    File tempFile = temporaryFolder.newFile("patterdale.yml");
    FileWriter fileWriter = new FileWriter(tempFile);
    fileWriter.write("invalid content");
    fileWriter.flush();

    assertThatThrownBy(() -> configUnmarshaller.parseConfig(tempFile))
            .isExactlyInstanceOf(IllegalArgumentException.class)
            .hasMessage(format("Error occurred reading config file '%s'.", tempFile.getName()))
            .hasCauseExactlyInstanceOf(JsonMappingException.class);
}
 
開發者ID:tjheslin1,項目名稱:Patterdale,代碼行數:13,代碼來源:ConfigUnmarshallerTest.java

示例15: writeToFile

import java.io.FileWriter; //導入方法依賴的package包/類
private static void writeToFile(final File file, final String value) throws IOException {
  final FileWriter writer = new FileWriter(file);
  writer.write(value);
  writer.flush();
  writer.close();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:7,代碼來源:FileProcessControllerIntegrationJUnitTest.java


注:本文中的java.io.FileWriter.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。