该“Frankenstein-ed”Java的第一部分完美工作,但第二部分输出一些混乱的废话。所以结果的变量将是我的用户输入。由于某种愚蠢的原因,我必须首先处理UpperCase字符串,但是当你来自数据库/分析背景并且知道你在几秒钟内做了某些事情并且没有发现错误时,很难。我在信用证到期时给予了信用代码...解析字符串输出到文件
myfile.txt的---> [Ljava.lang.String内; @ 19821f
import java.io.*;
/*http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29*/
public class StringParser {
public static void main (String arg[])
throws FileNotFoundException {
String result = "eggs toast bacon bacon butter ice beer".toUpperCase();
String[] resultU = result.split("\\s");
String[] y = resultU;
{
for (int x=0; x< resultU.length; x++)
System.out.println(resultU[x]);
/*http://www.javacoffeebreak.com/java103/java103.html#output*/
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
try
{
// Create a new file output stream
// connected to "myfile.txt"
out = new FileOutputStream("myfile.txt");
// Connect print stream to the output stream
p = new PrintStream(out);
p.println (resultU);
p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
}
}
}
我是新来的Java,所以我试图通过把我的脚去火学习... :)谢谢..让我试试看... – Darren
很感谢H.D.! – Darren
@Darren你应该选择这个作为正确答案然后;) –