🔒 Closed Help po sa java I/O Classes!!!

Status
Not open for further replies.

Nero Swallowtail

Honorary Poster
umay ,bat my error/exception sya? pano po ba to ayusin?
1618756576655.webp

tapos kahit dun sa execution mali,kase ito po yung original txt file nya
1618756652086.webp

pa help po sana, puro key word asa handout walang example ih HAHAHA
eto ung code.
JavaScript:
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;

public class TaskPer6 {
    static String files;
    static Scanner scan = new Scanner(System.in);
    
    

    public static void main(String[] args) throws IOException {
        TaskPer6 Task = new TaskPer6();
        Path file = Paths.get("C:\\Users\\Asta\\Documents\\Looping.txt");
        /*
        System.out.println(file.toString());
        System.out.println(file.getName(3));
        System.out.println(file.getFileName());
        System.out.println(file.getNameCount());
        
        
        
        for(int n = 0; n<= 3; n++) {
            System.out.println("File Names are " + file.getName(n));
            
            
        }*/
        
        System.out.println();
        
            
            File newFile = new File("C:\\Users\\Asta\\Documents\\TextFile.TXT");
            Scanner scan = new Scanner(newFile);
    
            String empty = "";
            while(scan.hasNextLine()) {
            System.out.println(scan.nextLine());
            empty = empty.concat(scan.nextLine() + "\n");
            }
            
            FileWriter writer = new FileWriter("C:\\Users\\Asta\\Desktop\\Try5.txt");
            writer.write(empty);
            writer.close();
            /*System.out.println(newFile.getName());
            System.out.println(newFile.getAbsolutePath());
            System.out.println(newFile.canRead());
            System.out.println(newFile.canWrite());
            */
            
            
            
            
            /*BasicFileAttributes fileAtt = Files.readAttributes(file, BasicFileAttributes.class );
            long Size = fileAtt.size();
            
            
            System.out.println("The File Size is " + Size);
            FileTime time =  fileAtt.creationTime();
            System.out.println("File created at: " + time);
            int time1 = file.compareTo(file);
            System.out.println(time1);
            FileTime time2 = fileAtt.lastModifiedTime();
            System.out.println(time2);
            System.out.println(newFile.createNewFile());
            
        }
        catch(IOException e) {
            System.out.println("IO Exception");
        }*/
        
        
        
        
        

    }
    
    public void absolute() {
        
        System.out.println("\nPrompt");
        
        files = scan.nextLine();
        Path path = Paths.get(files);
        Path newPath = path.toAbsolutePath();
        
        System.out.println(files);
        
        System.out.println("Hakdog " + newPath);


        
    }
    
}
 
Dito po sa part na to may error
while(scan.hasNextLine()) {
System.out.println(scan.nextLine());
empty = empty.concat(scan.nextLine() + "\n");
}

especially,
empty.concat(scan.nextLine() + "\n");

Pwede nyo pong palitan yung condition sa while loop ng
Java:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class JavaIO {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("C:\\Users\\Arcturus\\Desktop\\test.txt");
        Scanner sc = new Scanner(file);
        String source = new String();
        while(sc.hasNext())
            source = source.concat(sc.next() + "\n");
        sc.close();
        System.out.println(source);
    }
}
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 605
    Views
  • 2
    Participants
Last reply from:
Arcturus

Online now

Members online
1,023
Guests online
1,452
Total visitors
2,475

Forum statistics

Threads
2,277,057
Posts
28,974,016
Members
1,229,706
Latest member
mxmmo
Back
Top