私はオンラインのJavaクラスにいて、課題に苦労していて、教え方がわからないので具体的に尋ねました:
「dteDateと呼ばれるGregorianCalendarオブジェクトを作成してください。 parseInt(.ファイルから一連の文字列を抽出し、それらを整数に変換し、GregorianCalendar オブジェクトを作成してから、フォーマットされた文字列に変換します。確かに最も効率的な方法ではありませんが、日付変数を作成する能力をテストします."
テキストファイルから特定の行を抽出する方法がわかりません.全体を抽出する方法だけでなく、私のプログラムがこのように見えるガイダンスをいただければ幸いです.
import java.io.*;
import java.nio.file.*;
import java.util.GregorianCalendar;
public class a19010
{
public static void main(String[] args)
{
Path objPath = Paths.get("dirsize.txt");
if (Files.exists(objPath))
{
File objFile = objPath.toFile();
try(BufferedReader in = new BufferedReader(
new FileReader(objFile)))
{
String line = in.readLine();
while(line != null)
{
System.out.println(line);
line = in.readLine();
}
}
catch (IOException e)
{
System.out.println(e);
}
}
else
{
System.out.println(
objPath.toAbsolutePath() + " doesn't exists");
}
GregorianCalendar dteDate = new GregorianCalendar();
}
}
これにより、テキスト ファイル全体がコンソールに出力されます。これは、Assinment の最初のステップであり、GregorianCalendar dteDate を作成しました。カレンダーに関連情報を提供するために必要な行を抽出する方法と、このプログラムのこの時点で何をすべきかわかりません。この投稿で多くの言葉を使いたくないので、質問への回答を難しくしたくないので、テキストファイルから関連する行を投稿してください。質問にさらに情報を追加したり、一部を取り出したり、明確にする必要がある場合はお知らせくださいそして私はそれを編集します。テキスト ファイル内の日付と時刻を含む行は、その最初の 4 行であり、次のとおりです:(明確にするために同様のコードを挿入します)
The current date is: Thu 03/28/2013
Enter the new date: (mm-dd-yy)
The current time is: 12:41:26.31
Enter the new time:
誰かが何をすべきかを知っているか、これを行う方法について正しい方向に向けることさえできれば、私は助けに感謝します.
これは、Bhushan Bhangale の助けを借りて到達したコードですが、カレンダーにインポートするのに問題があります。
String line = in.readLine();
int lineNum = 1;
//extract the month
String monthSubstring = line.substring(25,27);
int month = Integer.parseInt(monthSubstring) -1 ;
//extact the year
String yearSubstring = line.substring(31,35);
int year = (Integer.parseInt(yearSubstring));
//extract the date
String daySubstring = line.substring(28,30);
int day = Integer.parseInt(daySubstring);
while(line != null)
{
System.out.println(line);
line = in.readLine();
lineNum ++;
if (lineNum == 3)
{
//extract the hour
String hourSubstring = line.substring(21,23);
int hour = Integer.parseInt(hourSubstring);
//extract the minute
String minuteSubstring = line.substring(24,26);
int minute = Integer.parseInt(minuteSubstring);
//extract the second
String secondSubstring = line.substring(27,29);
int second= Integer.parseInt(secondSubstring);
}
}
GregorianCalendar dteDate = new GregorianCalendar(year, month, day, hour, minute, second);
System.out.println(dteDate.getTime());
問題は、カレンダーが時分または秒を見ることができず、それらをインポートする方法がわからないことです