Java中如何实现刷新功能
1个回答
展开全部
这里面的writer.flush();方法是刷新的意思不知道是不是你想要的。
public
class
Io
{
public
static
void
main
(String
[]
args)throws
Exception{
File
f=new
File(args[0]);
f.createNewFile();
new
File("test1").mkdir();
//
make
new
dir
File
f2=new
File("test1"
+
File.separator
+args[0]);
f2.createNewFile();
System.out.println(f2.getName());
System.out.println("
Absolute
Path
is:
"
+
f2.getAbsolutePath());
System.out.println("
Can
Read
:?
"
+
f2.canRead());
f2.renameTo(new
File("test"
+
File.separator+
"newfile"));
Io
i=new
Io();
i.writeOneLine(args[0]+".csv","测试,ghmn,你们,\nafd,asdf,\neee");}
public
void
writeOneLine(String
name,String
line){
PrintWriter
writer
=
null;
try
{writer
=
new
PrintWriter(new
FileWriter(name,
true));
writer.println(line);
writer.flush();
}
catch
(IOException
e)
{
System.out.println("Error:
"
+
e);}
finally
{
writer.close();}
}
public
class
Io
{
public
static
void
main
(String
[]
args)throws
Exception{
File
f=new
File(args[0]);
f.createNewFile();
new
File("test1").mkdir();
//
make
new
dir
File
f2=new
File("test1"
+
File.separator
+args[0]);
f2.createNewFile();
System.out.println(f2.getName());
System.out.println("
Absolute
Path
is:
"
+
f2.getAbsolutePath());
System.out.println("
Can
Read
:?
"
+
f2.canRead());
f2.renameTo(new
File("test"
+
File.separator+
"newfile"));
Io
i=new
Io();
i.writeOneLine(args[0]+".csv","测试,ghmn,你们,\nafd,asdf,\neee");}
public
void
writeOneLine(String
name,String
line){
PrintWriter
writer
=
null;
try
{writer
=
new
PrintWriter(new
FileWriter(name,
true));
writer.println(line);
writer.flush();
}
catch
(IOException
e)
{
System.out.println("Error:
"
+
e);}
finally
{
writer.close();}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询