本文整理汇总了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();
}
}
示例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为空!");
}
}
示例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);
}
}
}
示例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;
}
示例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为空!");
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
}
}
示例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);
}
}
示例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();
}
}
示例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 *********");
}
示例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();
}
}
示例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()));
}
}
示例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);
}
示例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();
}