سلام
من می خواهم برنامه ای به استفاده از جاوا بنویسم که در آن محتوای فایلی را بخواند و بعد ویرایش کند . ولی نمی دونم باید از چه متد هایی استفاده کنم .
لطفا راهنمایی کنید .
با تشکر
سلام
من می خواهم برنامه ای به استفاده از جاوا بنویسم که در آن محتوای فایلی را بخواند و بعد ویرایش کند . ولی نمی دونم باید از چه متد هایی استفاده کنم .
لطفا راهنمایی کنید .
با تشکر
سلام
سوال من درموردپیدا کردن الگوریتم کوتاهترین مسیر است
و پیدا کردن ساختمان cd می باشد.
هر کسی چیزی می دونه بسم ا..
برای خواندن و نوشتن روی هارد از :
____________________________
همه چیز را همگان دانند و همگان هنوز از مادر زاده نشده اند. (بزرگمهر حکیم)
خیلی ممنون از جوابتون خیلی کمکم کرد .
یه سوال ؟
می خواستم بدونم آیا می تونم محتوای فایلی را تغییر بدم ؟
____________________________
همه چیز را همگان دانند و همگان هنوز از مادر زاده نشده اند. (بزرگمهر حکیم)
سلام
من ی مشکل دارم میخوام روی اطلاعاتی که تو فایلم هست سرچ کنم به این صورت:
1,علی,حسینی,2281545
2,رضا,رضایی,6584135
میخوام عدد از کاربر بگیره تو فایلم سرچ کنه بعد اطلاعاتشو چاپ کنه مثلا اگه زد 2 چاپ کنه 2,رضا,رضایی,6584135
چجور میتونم این کارو کنم ؟؟؟؟؟؟؟
سلام
یه سوال داشتم می خواستم ببینم برای خوندن و نوشتن در جاوا غیر از Scanner چه راه هایی هست ؟
ممنون :)
سلام من یک فایل 2گیگابایتی دارم که میخوام 1 مگ 1 مگ بخونم ازش.ممنون میشم راهنماییم کنین.
سلام. چیزی که پیشنهاد میکنم، استفاده از MappedByteBuffer هست. بخشی از documentation کلاس MappedByteBuffer :
/**
* A direct byte buffer whose content is a memory-mapped region of a file.
*
* <p> Mapped byte buffers are created via the {@link
* java.nio.channels.FileChannel#map FileChannel.map} method. This class
* extends the {@link ByteBuffer} class with operations that are specific to
* memory-mapped file regions.
*
* <p> A mapped byte buffer and the file mapping that it represents remain
* valid until the buffer itself is garbage-collected.
*
* <p> The content of a mapped byte buffer can change at any time, for example
* if the content of the corresponding region of the mapped file is changed by
* this program or another. Whether or not such changes occur, and when they
* occur, is operating-system dependent and therefore unspecified.
*
تا جایی که میدونم سریع ترین راه برای خوندن فایلهای بزرگ تو جاوا همین MappedByteBuffer هست.
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
/**
* @author avb
*/
public class LargeFileReadTest {
static final int FILE_CHUCK_SIZE = 1073741824; //1 GB
static final int BUFFER_SIZE = 1048576; //1 MB
public static void main(String[] args) throws IOException {
String fileName = "D:\\LargeFile.txt";
try (FileChannel inChannel = FileChannel.open(Paths.get(fileName))) {
long pos = 0, size = inChannel.size(), chunkSize;
while (size > 0) {
chunkSize = Math.min(FILE_CHUCK_SIZE, size);
MappedByteBuffer mappedByteBuffer = inChannel.map(FileChannel.MapMode.READ_ONLY, pos, chunkSize);
read(mappedByteBuffer);
mappedByteBuffer.clear();
size -= chunkSize;
pos += chunkSize;
}
}
}
static void read(MappedByteBuffer mappedByteBuffer) throws IOException {
byte[] bytes = new byte[BUFFER_SIZE];
while (mappedByteBuffer.hasRemaining()) {
int len = Math.min(bytes.length, mappedByteBuffer.remaining());
mappedByteBuffer.get(bytes, 0, len);
process(bytes);
}
}
static void process(byte[] bytes) throws IOException {
//process bytes
}
}
من خودم روی یه فایل متنی حدودا 3 گیگی تست کردم و بدون مشکل تونستم فایل رو بخونم.
آخرین ویرایش به وسیله ahmad.mo74 : یک شنبه 20 اردیبهشت 1394 در 16:36 عصر
خیلی ممنون
اگه بخوام از buffered reader استفاده کنم چجوری میشه؟
سلام. بله از buffered reader هم میتونید استفاده کنید. اما پیشنهاد من همون MappedByteBuffer هست چون برای فایلی با این حجم خیلی مناسب تر و سریع تره.
static final int BUFFER_SIZE = 1048576;
public static void main(String[] args) throws IOException {
try (FileReader fileReader = new FileReader("D:/a.txt");
BufferedReader reader = new BufferedReader(fileReader)) {
char[] buf = new char[BUFFER_SIZE];
while (reader.read(buf) != -1) {
process(buf);
}
}
}
static void process(char[] chars) {
}
از این کد استفاده کنید :
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
/**
* @author avb
*/
public class LargeFileReader {
static final int BUFFER_SIZE = 1024 * 1024;
static void readFile(String fileName) throws IOException {
try (FileChannel inChannel = FileChannel.open(Paths.get(fileName))) {
long pos = 0, size = inChannel.size(), chunkSize;
MappedByteBuffer mbb;
while (size > 0) {
chunkSize = Math.min(Integer.MAX_VALUE, size);
mbb = inChannel.map(FileChannel.MapMode.READ_ONLY, pos, chunkSize);
readBuffer(mbb);
mbb.clear();
size -= chunkSize;
pos += chunkSize;
}
}
}
static void readBuffer(MappedByteBuffer mappedByteBuffer) throws IOException {
while (mappedByteBuffer.hasRemaining()) {
int len = Math.min(BUFFER_SIZE, mappedByteBuffer.remaining());
byte[] bytes = new byte[len];
mappedByteBuffer.get(bytes);
process(bytes);
}
}
static void process(byte[] bytes) throws IOException {
String s = new String(bytes);
//...
}
public static void main(String[] args) throws IOException {
String fileName = "D:\\large.txt";
readFile(fileName);
}
}
آخرین ویرایش به وسیله ahmad.mo74 : یک شنبه 20 اردیبهشت 1394 در 17:46 عصر
سلام ببخشید میشه در مورد java logging log 4j توضیح بدهید و اینکه چطوری میشه اطلاعات log را در database مثل postgresذخیره کرد؟؟؟؟؟؟ممنون میشم راهنمایی کنین!خیلی ضروریه