简体   繁体   English

Java中'\\ f'char的替代方法是什么?

[英]What is the alternative for '\f' char in Java?

I have an Application that writes some texts in a file . 我有一个在文件中写入一些文本的应用程序。 Each five lines must be in distinct page. 每五行必须在不同的页面中。 I have to use Dot Matrix Printers that invoke continuous pages also I use \\f for indicating new page. 我必须使用调用连续页面的Dot Matrix Printers ,也要使用\\f来指示新页面。 There is no problem in about writing file. 写文件没有问题。 But there is a problem when I print text file. 但是当我打印文本文件时出现问题。

When printer prints first \\f char , it invokes page completely without printing rest of the file. 当打印机首先打印\\f char时,它将完全调用页面而不打印文件的其余部分。 If I cut continuous page and insert them distinctly, all things will be good, but it is not a good way for printing files that have more than 100 pages. 如果我剪切连续的页面并清楚地插入它们,那么一切都会很好,但这不是打印多于100页的文件的好方法。 How can I solve this problem? 我怎么解决这个问题?

The simplest way to implement a page break as you would like is to insert unicode character 12, which is a form feed (FF) in ASCII and UTF. 如您所愿,实现分页符的最简单方法是插入Unicode字符12,这是ASCII和UTF格式的换页(FF)。 This will be interpreted by both Microsoft's Word and the WordPad application that ships with Windows, and a page break will be inserted correctly. Microsoft的Word和Windows附带的WordPad应用程序都将对此进行解释,并且将正确插入分页符。 You could achieve this in the following code: 您可以通过以下代码实现:

import java.io.File;  
import java.io.FileWriter;

public class PageBreakTest {  
    public static void main(String[] args) throws IOException {  
        File f = new File("page.doc");  
        FileWriter fw = new FileWriter(f);  
        fw.write("Page 1 information" + (char)12);  
        fw.write("Page 2 after page break char");  
        fw.close();  
    }  
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM