Random Acess 이용한 자바
하루키
정말 급한데요 부탁드려요!!당신이 하드워어 사장이고목록저장하는것이 필요하다
그것을 다른 무슨도구를 너는 가지고 있으며,
얼마나 많은 각각의 것을 가지고 있으며,
그리고 각각의 가격에 대해서.
당신에게 알려준다.
프로그램을 써서 레코드 아이템을 정의 하고 목록과 각각 도구에 대해서 데이타를 넣으시오.
Random access file 만들고요 쓰는 레코드 파일하고
그런다음 전부 레코드를 쓰고,
최초파일로가고 그리고레코드가 교체하도록 프린트하십시오*********밑에 비슷한 예제 있습니다**********
You are the owner of a hardware store and need to keep an inventory
that can tell you what different tools you have, how many of each
you have on hand, and the cost of each one.
Write a program that defines a record of items in the inventory and
inputs the data concerning each tool. Create a Random access file and
write the records to the file. After you have written all records,
go to the beginning of the file and print every alternate record.
Use the following info for the records:
예제.
import java.io.*;
public class RandomFileTest
{
static String filename = numbers.txt;
final static int INT_SIZE = 4;
public static void main(String[] args)
{
try {
RandomFileTest F = new RandomFileTest();
F.createFile();
F.readFile();
F.extendFile();
F.readFile();
}
catch (IOException e)
{
System.out.println(e);
}
}
// Create a file with squares of numbers from 0 to 9
public void createFile() throws IOException
{
File dataFile = new File(filename);
RandomAccessFile ofile = new RandomAccessFile(dataFile, rw);
for (int i = 0; i 10; i++)
ofile.writeInt(i*i);
ofile.close();
}
// Read every other number from the file
public void readFile() throws IOException
{
File dataFile = new File(filename);
RandomAccessFile ifile = new RandomAccessFile(dataFile, r);
System.out.println(Read squares of Odd numbers from the file);
long length = ifile.length();
System.out.println(File Size: + length);
for (int i = INT_SIZE; i length; i += 2*INT_SIZE)
{
System.out.println(Offset = + i);
ifile.seek(i);
System.out.println(ifile.readInt());
}
ifile.close();
}
// Extend the file with squares from 10 to 19
public void extendFile() throws IOException
{
RandomAccessFile oFile = new RandomAccessFile(filename, rw);
oFile.seek(oFile.length());
for (int i = 10; i 20; i++)
oFile.writeInt(i*i);
oFile.close();
}
}
-
맨삶이
숙제는 스스로..
-
흰양말
와~~ 문제은행으로 가야할게 왜 여기있나 했다는... ㅡ_ㅡ;;;;
-
클
죄송합니다.
요구 사항도 애매 할 뿐더러 무분별한 과제 요청은 바로 강퇴입니다.
경고차원에서 재 가입 가능하도록 강퇴만 했으니 참고하시기 바랍니다. -
낶아
질문에는 말머리~! ^^;;
그리고 과제는 왠만하면 ㅎㅎ;;; 스스로해결해보시는게;