2012-03-08 56 views
0

我的问题是。我正在编写一个程序进行预订。为此,我使用Filewriter和Buffered写入将其写入txt文件。输入是通过simpleInoutDialog进行的,它给出了一个带模板hh:mm:ss的字符串。用Filewriter写入的txt文件中的排序时间

这是我写txt文件使用一个名称 例如,沿着:

08:00:00 
Tom Hanks 
06:20:00 
Henry Bigs 

排序的日期,这样我可以轻松地阅读它我想要做的是什么? 有什么帮助吗?

回答

0

是的。使用,使图案:

<configuration> 

    <appender name="FILE" class="ch.qos.logback.core.FileAppender"> 
    <file>testFile.log</file> 
    <append>true</append> 
    <!-- encoders are assigned the type 
     ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> 
    <encoder> 
     <pattern>%date{HH:mm:ss} - %msg%n</pattern> 
    </encoder> 
    </appender> 

    <root level="DEBUG"> 
    <appender-ref ref="FILE" /> 
    </root> 
</configuration> 

框架会为您挑选的消息。

+0

此代码需要在我的java代码中才能使用? – PauloPawelo 2012-03-08 21:02:42

+0

将logback.xml添加到您的项目中 - 我包含上面的内容,详情请参阅[Logback manual](http://logback.qos.ch/manual/index.html)。添加[logback-classic](http://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.0.0),[logback-core](http://mvnrepository.com/artifact/ch。 qos.logback/logback-core/1.0.0)和[slf4j-api](http://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.6.4)添加到您的类路径中。并参见[slf4j手册](http://www.slf4j.org/manual.html)。我更喜欢Maven项目,因为那时所有的依赖都是为我提供的。 – 2012-03-08 21:13:11