저는 이클립스에서 파일을 입력으로 사용하고 출력으로 새 파일을 작성하는 Java 프로그램을 작성하고 있습니다. 일부 논리를 따릅니다.DataOutputStream.write (int b)는 쓰지 않습니다.
나는 입력 파일에 대해 datainputstream을 사용하고 출력 파일에 대해서는 dataoutputstream을 사용합니다. 잘 작동하는 readln() 메서드에 사용합니다.
이제 write() 메서드에 문제가 생겼습니다. 아무 것도 쓰지 않습니다. 입력에 대해 randomAccess를 시도한 다음 출력에 대해 bufferedoutputstream을 tryed했습니다.
내가 별도의 자바 프로젝트에 tryed 한이 : 쓰기 위의 코드에서
import java.io.*;
import javax.swing.*;
public class apri_file {
@SuppressWarnings("deprecation")
public static void main(String[] args){
File inputFile = null;
File outputFile = null;
String dati;
int dato;
try {
JFileChooser FileWindow = new JFileChooser();
FileWindow.isDirectorySelectionEnabled();
FileWindow.setApproveButtonText("Open IPL File");
if(FileWindow.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
inputFile = FileWindow.getSelectedFile();
System.out.println("input path: " + inputFile.getAbsolutePath());
}
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
System.out.println("input buffer reader created");
/**************************/
FileWindow.setApproveButtonText("Save PLY FIle");
if(FileWindow.showSaveDialog(null) == JFileChooser.APPROVE_OPTION){
outputFile = new File (FileWindow.getSelectedFile(),"");
System.out.println("output path: " + outputFile.getAbsolutePath());
}
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream (outputFile)));
/**************************/
/*
* to do write header
*/
for(int i=0;i<inputFile.length();i++){
dati = in.readLine();
if(dati == null){
break;
}
if(dati == "vnod"){
while(in.read() != 0X65){
dato = in.read();
if(dato == 0X09 || dato == 0X0D || dato == 0X2C){ }
else if(dato == 0X2E) out.write(0X2C);
else out.write(dato);
}
}
if(dati == "link"){
int virgola = 0;
dato = in.read();
while(dato != 0X65){
if(virgola < 4){
if(dato == 0X2C) virgola++;
if(dato == 0X09 || dato == 0X0D){}
else out.write(dato);
}
else{
while(dato != 0X0D) {
dato = in.read();
}
virgola = 0;
out.write(0X0D);//nl
out.write(0X34);//4
out.write(0X20);//space
}
dato = in.read();
}//while link
end = true;
}//if link
}//while file
//testing the write() method
for(int i=0; i<1000; i++){
out.write(0X2C); //tricky part! this output will be always written!! WTF!
}
in.close();
out.close();
JOptionPane.showMessageDialog(null, "Done!", "Done!" , JOptionPane.INFORMATION_MESSAGE);
}
catch (IOException e){
System.out.println(e + "\n");
}
}
}
(INT :
public static void main (String[] args){
File output = new File("MyOutputDirectoryHere");
try{
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream (output)));
for(int i=0; i<1000; i++){
dos.write(i);
}
dos.close();
}
catch (IOException e){
System.err.println(e);
}
}
하고
하지만 완벽하게 작동이 엉망 내부 b) 메서드는 for 루프를 제외한 나머지 코드를 데스크톱의 출력 파일에 쓰지 않습니다 ... 코드 부분이 잘 작동합니다 ...
나는 무엇을 해야할지 잘 모릅니다. 도와주세요.
'dati'가 실제로 "vnod"또는 "link"와 같은 것을 확인 했습니까? – vegasje
예제 IPL 파일이 있습니까? –
내 답변을 참조하여 문제를 해결하십시오. 매우 일반적인 함정입니다. 누군가 C++에서 java에 이르면. 또한 디버거를 사용하여 익숙해지기를 권장합니다. – Joe