Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package iokol2016;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileFilter;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.FilenameFilter;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- /**
- *
- * @author jimmy
- */
- public class IOkol2016 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- //zapisaj("text.txt","napocetok.txt");
- //zapisajSoBuff("text.txt","sobuf.txt");
- //napocetok("text.txt","odpocetok.txt");
- //napocetok("text1.txt","odpocetok.txt");
- ///javatxt("odpocetok.txt","java.txt");
- filter(".");
- }
- public static void zapisaj(String in , String out) throws FileNotFoundException, IOException{
- File in1=new File(in);
- File out1=new File(out);
- RandomAccessFile r=new RandomAccessFile(in1,"r");
- RandomAccessFile rw=new RandomAccessFile(out1,"rw");
- try{
- int kraj=(int) r.length();
- int poc=0;
- byte[] bajt = new byte[kraj];
- int c;
- rw.seek(rw.length());
- while((c=r.read(bajt))!=-1){
- rw.write(bajt,0,kraj);
- }
- }finally{
- if(rw!=null){
- rw.close();
- }
- if(r!=null){
- r.close();
- }
- }
- }
- public static void zapisajSoBuff(String in, String out) throws FileNotFoundException, IOException{
- File in1 = new File(in);
- File out1=new File(out);
- FileReader fr = new FileReader(in1);
- BufferedReader br=new BufferedReader(fr);
- FileWriter fw=new FileWriter(out1,true);
- BufferedWriter bw = new BufferedWriter(fw);
- try{
- String s;
- while((s=br.readLine())!=null){
- bw.write(s);
- }
- }finally{
- if(bw!=null){
- bw.close();
- }
- if(br!=null){
- br.close();
- }
- }
- }
- public static void napocetok(String in ,String out) throws FileNotFoundException, IOException{
- File in1 = new File(in);
- File out1=new File(out);
- RandomAccessFile r=null;
- RandomAccessFile rw=null;
- try{
- r=new RandomAccessFile(in,"r");
- rw=new RandomAccessFile(out,"rw");
- rw.seek(rw.length());
- int kraj=(int) r.length();
- byte[] bajt=new byte[kraj];
- int c;
- while((c=r.read(bajt))!=-1){
- rw.write(bajt,0,kraj);
- }
- }finally{
- if(r!=null){
- r.close();
- }
- if(rw!=null){
- rw.close();
- }
- }
- }
- public static void javatxt(String in , String out) throws FileNotFoundException, IOException{
- RandomAccessFile r=null;
- RandomAccessFile rw=null;
- try{
- r=new RandomAccessFile(in,"r");
- rw=new RandomAccessFile(out,"rw");
- //rw.seek(rw.length());
- int kraj=(int) r.length();
- byte[] bajt=new byte[kraj];
- int c;
- while((c=r.read(bajt))!=-1){
- rw.write(bajt,0,kraj);
- }
- }finally{
- if(r!=null){
- r.close();
- }
- if(rw!=null){
- rw.close();
- }
- }
- }
- public static void filter(String in){
- FileFilter file = new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- return pathname.isFile() && pathname.getName().endsWith(".dat");
- }
- };
- FilenameFilter name = new FilenameFilter(){
- @Override
- public boolean accept(File dir, String name) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- String ime = name.toLowerCase();
- if(ime.endsWith(".txt")){
- return true;
- }
- else
- return false;
- }
- };
- File f = new File(in);
- for(File f1 : f.listFiles(file)){
- System.out.println(f1.getName());
- }
- for(File f1 : f.listFiles(name)){
- if(f1.isFile()){
- System.out.println(f1.getName() + " " +f1.getAbsolutePath());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement