私のプログラムはZuessファイルを読むことができるはずですファイルを開いてJavaの最初の単語を削除する
私を見てください!
私を見てください!
今すぐ見る
楽しいことが楽しいです
しかし、あなたは
を知っています。
各行の最初の単語を削除しながら新しいファイルを作成します。プログラムを実行すると、最初の単語が削除されます。
Courier;}
\cf0 \expnd0\expndtw0\kerning0
at me!\
at me!\
at me NOW!\
is fun to have fun\
you have\
know how.\
私はNEWFILE.TXTだけではない、誰かが助けてくださいすることができますファイルに実際にあるものを手に入れるファイル内にあるものを印刷しようとすると、それは最後に、書き込み何です。
//Program that removes the first word from every line in a file
import java.io.*;
import java.util.Scanner;
public class test {
//Main Method
public static void main (String args[])
{
//Get the system defined
String newLine = System.getProperty("line.separator");
//Name of original file
String origFileName = "zuess.RTF";
//Name of new file
String newFileName = "NewFile.txt";
//Creating the PrintWriter
PrintWriter outputStream = null;
try {
outputStream = new PrintWriter
(new File(newFileName));
} catch (FileNotFoundException e1) {
System.out.println("Error opening the file " + origFileName);
System.exit(0);
}
//Create scanner
Scanner inputStream = null;
try {
inputStream = new Scanner
(new File(origFileName));
} catch (FileNotFoundException e1) {
System.out.println("Error opening the file " + origFileName);
System.exit(0);
}
//While there's lines in the the file
while(inputStream.hasNextLine())
{
//get line in original file
String line = inputStream.nextLine();
//split line to get words
String[] arr = line.split(" ");
for(int i = 1; i < arr.length; i++)
{
//So the data will print in the new file
outputStream.write(arr[i] + " ");
}
//Line separator
outputStream.write(newLine);
}
//Close Stream
outputStream.close();
inputStream.close();
//catch exception
try
{
inputStream = new Scanner(new File (newFileName));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file " + newFileName);
System.exit(0);
}
System.out.println("The file " + newFileName + " Contains the following lines: ");
while (inputStream.hasNextLine())
{
String text = inputStream.nextLine();
System.out.println(newFileName);
}
inputStream.close();
}//End main
}//end class
をバージョンを使用している私はそれをしたいですただ書きなさい: 私に!私に ! 今すぐ! は楽しいです。 あなたは ノウハウを持っています。 –
私を見て! 私を見て! 今見てください! 楽しみが楽しいです しかし、あなたはどのように知って 持っています。 –
元のファイルの内容です。 –