English 中文(简体)
Java; 从投入文本文档到产出文本文档的线断
原标题:Java; Line breaks from input text file to output text file

首先,这是第一组方案拟定工作,因此,如果这是一个非常简单的问题,我会抱歉。 就家务劳动而言,我们必须起草一个方案,对文本档案进行扫描,促使用户使用“斜线”确定的措辞,然后将结果写到另一个文本档案中。

问题Im是,产出文件都是在单一行文上书写的,而不是保留从投入文件上分离的线。

For example:

投入

like

本案文。

the output like本案文。

This is the code I have in the relevant method.

public static void createMadLib(Scanner console) throws FileNotFoundException {
    Scanner input = getInput(console);
    System.out.print("Output file name: ");     
    PrintStream out = new PrintStream(new File(console.nextLine()));
    System.out.println();

    String text = input.next();
            while (input.hasNext()){


                    if (text.startsWith("<")){
                        text = text.substring(1, text.length()-1);
                        text = text.replace("-"," ");
                        if ((text.startsWith("a"))||(text.startsWith("e"))||(text.startsWith("i"))||(text.startsWith("o"))||(text.startsWith("u"))){                        
                            System.out.print ("Please type an " + text + ": ");
                            text = (console.nextLine());
                        }else {
                            System.out.print ("Please type a " + text + ": ");
                            text = (console.nextLine());
                        }
                    }
                    out.print(text + " "); 

                    text = input.next();

            }//ends while loop  
    out.print(text);
    prompt(console);
    }

I apologize for any formatting faux pas, again, this is my first programming class.

感谢您的帮助

最佳回答

Instead of using out.print, you may want to use out.println, which does the same thing, but appends a newline character to the end of the line. You can also manually concatenate the newline character ( ) where you wish to insert linebreaks.

问题回答

yep, Jonathan s answer will work. so i vote for Jonathan s,.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签