File splitter won't accept some text files
sorry, this is in the wrong place is there any way i can move it to general programming?
i'm making a file splitter to split large text files into smaller parts. so far everything works as far as test files that i make, however, sometimes when i copy and paste text off the internet, for example, the splitter does not import any of the text as if it can't recognize it. what might i be able to do to get it to recognize this kind of text. the files were saved as ANSI encoding, if it matters.
import java.util.*;
import java.lang.*;
import java.io.*;
public class FileSplitter
private File inFile;
private Scanner scan;
private String path;
private String filename;
private String ext;
private File outFile;
private String allData = "";
//max chars in the file
private final int FILE_LIMIT = 3500;
public FileSplitter(String path, String name)
try
this.path = path;
int dot = name.lastIndexOf('.');
this.filename = name.substring(0,dot);
this.ext = name.substring(dot,name.length());
this.inFile = new File(path+name);
this.scan = new Scanner(this.inFile);
catch(FileNotFoundException e)
e.printStackTrace();
System.out.println("File not found at:");
System.out.println(path+filename);
public void split()
while(scan.hasNextLine())
allData = allData.concat(scan.nextLine());
//maybe input an "allData = allData.concat(\n);"
int x = 0; // file portion sequence number
int currIndex = 0; // current index in "scan"
String writeToFile = "";
System.out.println(allData.length());
while(currIndex <= allData.length())
x++;
System.out.println("Making file "+x);
try
BufferedWriter out = new BufferedWriter(new FileWriter(path + filename + "-" + x + ext));
//System.out.println(currIndex);
//System.out.println(allData.length());
if(currIndex+FILE_LIMIT > allData.length())
writeToFile = allData.substring(currIndex, allData.length());
else
writeToFile = allData.substring(currIndex, currIndex+FILE_LIMIT);
out.write(writeToFile);
out.close();
catch (IOException e)
e.printStackTrace();
System.out.println("File write error.");
currIndex = currIndex + FILE_LIMIT;
public static void main(String[] args)
String path = "C:\\split\\";
String filename = "file.txt";
FileSplitter x = new FileSplitter(path, filename);
x.split();
System.out.println("Done.");
}the program works perfectly for most files, but certain ones, and i'm not sure how they differ, do not get read at all. Is there a kind of text that will not get read? all files were saved with notepad.
no error is thrown on these, but the length() function returns 0.
i've also tried using scan.next() and nextByte() as well, to no success, with appropriate hasNext...() calls
if anyone's wondering, this is to make files easily accessible to ipods with 4kb text file limits on what they can show.
i am now thinking of accepting web pages as raw source and parsing out <...>
Instead of using a Scanner why not use a BufferedReader which will handle files that use either '\n' or '\r' as line terminators. After all, all you are doing is reading the file in line by line and storing into a string with out the newline character.
Similar Messages
-
Encore won't encode some PSD files in Flash
I have succesfully completed a DVD project on Encore (4.0) with mpg elements edited in Premier Pro (4.0). A number of slide sequences constructed from jpgs converted
to pds files in Photoshop (cs5) have been used, plus some (individual, single) text slides, (constructed in Photoshop) have also been included with the DVD project. All of this works
fine. However, when I render the whole project for Flash, the text files are not included! During the render process the file details are displayed but no yellow progress bar appears.
The Flash file is prefereable to the DVD as this enables the Flash file to be available from a central common drive or server.
Can anyone assist me with this? I can find nor reference to these types of issues iether on the forum or anywhere on the net.
MAC Book Pro 17"
i5, 4 Gb Ram (Soon be 8)
Snow Leopard
Premier Pro 4.0
Encore 4.0
Photoshop CS5Hi Stan
And thanks for the prompt reply. I will try this twixt Christmas and new year. My recollection was that the text created in Premier
when imported into Encore looked “poor” as an mpg. However I had not rendered the project in Flash at that stage. Will
have to look at how Premier works direct to Flash without Encore?
Regards
From: Stan Jones [email protected]
Sent: 23 December 2011 13:25
To: Wheeler, Steve
Subject: Encore won't encode some PSD files in Flash
Re: Encore won't encode some PSD files in Flash
created by Stan Jones <http://forums.adobe.com/people/Stan+Jones> in Encore - View the full discussion <http://forums.adobe.com/message/4101020#4101020 -
Hi All,
powershell script Method required to read a value from registry and then taking the backup of that values in some text file.
For example the hive is
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path
and under path i need to take back up of values in some text file and then put some value in the registry after back is taken in text file.
Also how to read the text file values so that we can again write to registry hive back from the back up text file.
Your help is much appreciated.
Umeed4uI think you need to read this first:
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
Don't retire TechNet! -
(Don't give up yet - 12,830+ strong and growing) -
What does "extracted channel PDF" mean and why does it continually duplicate on my desktop? I think it happens when I move a file in Finder to another file and when I copy some web files. I have to immediately move to trash all the duplications on my desktop. How do I avoid this on my Mac (Mavericks)? Thanks for your help!
What application is set to open PDF files? If you CNTRL click on the file and open with Preview does the problem occur?
If not change the default application to open PDF files to Preview.
You can do this by highlighting the file and either use CMD i or Get Info , this will open a window with the info on the file with an option to change the application that opens the file.
That's all I can think of. -
My iPhone 5 with latest version of iOS 6 won't receive some text messages (not iMessages)
My IPhone 5 with latest version of ios 6 won't receive some text messages. All text messages not received are from different people on the same carrier (not mine). Some messages come through if they repeatedly send them. I have tried resetting network settings. This fixes the issue for 10 minutes or so before I don't receive the messages again. I dont have iMessage on and I've tried a restore.
Hi,
I had the same issue.
After resetting the network settings everything works fine again.
YouTube App and the videos you posted above didn't play.
After resetting, they are playable.
Try it out.
Best regards,
Tolga -
Preview won't print some PDF files
Hi everyone, I know a similar problem has been already discussed but it was not solved.
When I print some PDF files from Preview on a Lexmark C524 color laser printer, I get only figures and symbols but no text. If I print the same files on a HP 2100 it prints ok.
I thought it was the printer driver, but then I tried the same using Adobe Reader 9.1 and it prints fine on all printers. So my guess is that it might be some PDF version compatibility issue with Preview.
Any idea anybody?
You can find one of the PDF giving problems at the following address: http://www.pnas.org/content/106/1/97.full.pdf
Thank you,
A.Is there anything in Concole or the CUPS log (/var/log/cups/error_log)? It could be a font problem, but one of the places above should have some indication.
Hope this helps. -
Premiere won't accept new source files in slightly different formats...
I'm using CS3 (and I installed CS4 and got the same problem). I've created a video using six different source videos that were originally encoded in XVID. I now know that was a bad idea but at the time I didn't know how to convert the video so I went ahead and used them. Now my project crashes to the desktop whenever I open it without any sort of error message.
This is a project that I started over a year ago and I set it aside because I didn't want to deal with the issue, but I really want to finish this project. Now I have a better handle on what sort of codecs work well with premiere and I use Super C to convert the videos to a friendly format and I haven't had any problems with my projects crashing since then.
So now I've revisted the project that is crashing and I have tried converting the original source videos to a more friendly format, but hte problem is, even when I get it to a format that is pretty much exactly the same settings as the original (size, fps, etc) premiere won't accept it. When I open the project and it asks me "Where is the file..." I'll point to the new file and premiere tells me "The selected file cannot be linked because its type (video) does not match original file's type (audio and video)".. I try this after opening the project by right clicking on the asset and choosing "link media..." but of course I get the same error message.
What i've gotten done in the project is like 10 hours worth of work and it would be a shame to lose all of it just because Premiere is too picky about switching from one media type to another .. what are my options in getting this to work?Welcome to the forum.
Yes, Xvid is a delivery-only format for delivery-only, but you know that too.
What I would do would be to Open that original Project, and then Offline the original Video. If you named the converted files the same, except for the extension, you should be able to then Import the replacement files and manually replace those. Make sure that when you choose to Offline the Assets, that you do a Save_As, so that the original Project is NOT overwritten - keep it safe.
You might try to Relink from the Project Panel, before you do the Import. I do not know if that will be allowed, due to the extension difference, but that would be the easiest way, if it works. Try that first. With the material Offline, Rt-click on each AV file, and choose Link Media. If you used the same file names, you should be able to find the converted versions. Let us know if this works, or if you get rejected.
Good luck,
Hunt -
IPod won't accept a WAV file - why??
I have a 4th-gen iPod nano, and I need to copy some WAV files onto it. However, when I sync the iPod, the WAV files don't appear on the iPod (even though I have not received an error message about copying them). The WAV files are ones I recorded myself, and edited in the program GoldWave. They are PCM signed 24 bit mono files. Does the iPod nano not accept WAV files in the PCM signed 24 bit mono format? If not, how do I need to format the files in order to be able to play them back on my iPod? Thanks very much for any help you can give me!!!
I have .wav files on a pc and am trying to transfer them to an ipod classic to either listen to on the device or to transfer into itunes. These are voice recordings. All of the files transfered but they are corrupted. How do I this properly?
Plus..I'm in a bit of a rush.
Sheri -
FCPX won't accept ".dv" video file
Why won't FCPX won't accept what FCE used to work with??
This is the file type:Tom Wolsky wrote:
Start with one of the uncompressed base settings
If the original is DV, why go to uncompressed and not straight to ProRes? Uncompressed files will be huge (perhaps 7 times as large as ProRes, which is already massive) and I am not sure there will be much to gain, but I am willing to be enlightened. -
QuickLook fails to recognize some text files
QuickLook previews most but not all doc, txt, html, php and css files. QuickLook will work on one file and fail on an apparently identical file, where both open cleanly in the same application when double clicked.
In some but not all cases, file metadata (viewed in Path Finder) shows difference in UTI and/or "Type" fields where QuickLook works with one and not the other. However, this is not consistent, and in any event I cannot find a way to either edit UTI or Type fields, or set file associations based on UTI or Type (file associations seem to be limited to file extension).
This behavior is the same on my MBP and iMac.
Does anyone else see this problem? Any suggestions?Thanks for some of the ideas. Here is the status and info update so far:
Original location of photos were from an old PC in 2005 that was backed up onto this external hard drive. I recently came accross the hard drive and noticed that there were a large number of photos that had not yet been loaded into iphoto. This is where this all started.
Clicked and dragged from my external hard drive to the desktop - No success.
Iphoto version 9.3.2
Connected the external hard drive to my other computer (PC) and emailed a few to myself. From my Imac, opened my email and downloaded them to my desktop. It worked and iphoto recognized them. So I tried emailing more photos from my external hard drive connected to my Imac to myself again, this time not from another pc but from my Imac. No success. So the lesson so far is that somehow it is making a difference in the file when I email the files from another computer (PC) and then save them to my desktop on my Imac.
I attached images of both file info. The one to the left of the photo is from the "fixed" file that somehow Iphoto recognizes after emailing it to myself, and yes it is RGB color. The one to the Right is the info screen of the original file. I see no difference in the file type between the two. However, this is from an untrained eye.
Given the amount of photos (approx 1500) I would have to email myself, I would like to know if there is another way to fix these files in lieu of going through this round about and time consuming fix via email.
Sorry for the image orientation. Everytime I attached it, the image went sideways.
Thanks!! -
Windows Movie Maker won't accept my Quicktime file
can you give me the hints? I tried converting the quicktime file and it's worked, because now it has the windows media thumbnail, BUT it still doesnt work in the movie player..
Windows Movie Maker does not import MOV files as you surmised. Third party software is necessary to convert it for importation to WMM.
One such software(free) that works is: 'RAD Video Tools' from 'Bink and Smacker':
www.radgametools.com/bnkdown.htm
The RAD Video Tools software will allow you to convert MOV files to AVI files, which will import into WMM
A FAQ page on converting files w/the RAD s/w is here:
www.radgametools.com/binkhcon.htm
It may look intimidating at first but all you really need to do is:
1) Browse to your MOV file, select it, then click 'convert a file' at bottom menu.
2) Then in the new window that pops up, make sure the output file type is .AVI(the default output file type should be AVI), then click on 'convert' at right menu.
3) Import the newly created AVI file into WMM
Hope this is helpful,
Buzzhead -
WebLogic writes to a text file and an applet reads the text file
Hi there,
I need some help here!
I have an applet that needs to read from a text file:
final URL prtDataURL = new URL("http://" + getCodeBase().getHost() + ":" + getCodeBase().getPort() + "/ESTC/lib/prtDataFile.txt");
final URLConnection urlConn = prtDataURL.openConnection();
urlConn.setUseCaches(false);
urlConn.setDoInput(true);
urlConn.setDoOutput(false);
final InputStreamReader is = new InputStreamReader(urlConn.getInputStream());
final BufferedReader in = new BufferedReader(is);
String inputLine;
while ((inputLine = in.readLine()) != null){
String[] tmp = inputLine.split("§");
this.dateTime = tmp[0];
this.quanTot = Integer.parseInt(tmp[1]);
this.quanSco = Integer.parseInt(tmp[2]);
this.quanSef = Integer.parseInt(tmp[3]);
this.valTot = Double.parseDouble(tmp[4]);
this.valSco = Double.parseDouble(tmp[5]);
this.valSef = Double.parseDouble(tmp[6]);
in.close();
is.close();and this is ok.
Now I have the web server (WebLogic) that must write, at regular time intervals, to that file (prtDataFile.txt). The web application writes to the file (which belongs to the application).
I've tried open the file with the File object but since the war file is unexploded I can't get the real path!
I've tried open an url connection,
final URL url = new URL("http://10.191.33.249:16801/ESTC/lib/prtDataFile.txt");
final URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setDoInput(false);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(currentDate + "§" + quantTot + "§" + quantSco + "§" + quantSef + "§" + valTot + "§" + valSco + "§" + valSef);;
out.flush();
out.close();which seems a little stupid since I'm opening an URLConnection to the same place where the application is. Anyway it doesn't work, i.e., it doesn't write to the file but it doesn't gives me any errors or exceptions.
Is there another way to get this two pieces communicating?
Thanks in advanceI have almost the exact same problem, and I am in the same situation as you are with respects to the language.
I am simply trying to create a file and output some garbage to it but my applet always spits back a security violation. I've tried eliminating the restrictions on the applet runner I use but I still get the error.
My method:
debug = new Label() ;
debug.setLocation( 20, 20 ) ;
debug.setSize( 500, 15 ) ;
add( debug ) ;
// output
try
OutputStream file = new FileOutputStream( new File( "" + getCodeBase() + "output.txt" ) ) ;
byte[] buffer = { 1, 2, 3, 4, 5 } ;
file.write( buffer ) ;
file.close() ;
} catch( Exception e )
debug.setText( e.toString() ) ;
Can anyone tell why this isnt working? -
Creating 2D Array with info from file and Saving it to a text file
what im trying to do is take my nice little data structure and put it into a 2D array which i can copy and paste as code into my compiler... it takes TDPoints(like Point2D except has z value) which are in Faces(an arraylist of points, each face also has a color value), which are in objects(arraylist of faces, + other attributes)
for my sake im only working with one object, here is my code:
private void saveArrayToTXT(String name) throws IOException
double X;
double Y;
double Z;
FileOutputStream xos = new FileOutputStream("C:/Program Files/Xinox Software/JCreatorV3LE/MyProjects/ThreeDRemake/Files/" + name + ".txt");
DataOutputStream fos = new DataOutputStream(xos);//ObjectOutputStream oos = new ObjectOutputStream(fos);
//oos.writeObject(myObject);
//for(int ob = 0; ob < ((ArrayList)myObject).size(); ob++)
ThreeDObject object = (ThreeDObject)(((ArrayList)myObject).get(0));
fos.writeChars("{");
for(int shape = 0; shape < object.getFaces().size(); shape++)
fos.writeChars("{");
ArrayList faces = object.getFaces();
for(int count = 0; count < ((Face)(faces.get(shape))).getPoints().size(); count++)
X = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getX();
Y = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getY();
Z = ((TDPoint)(((Face)(faces.get(shape))).getPoints().get(count))).getZ();
fos.writeChars("" + (int)X);
fos.writeChars(",");
fos.writeChars("" + (int)Y);
fos.writeChars(",");
fos.writeChars("" + (int)Z);
if(count != ((Face)(faces.get(shape))).getPoints().size()-1)
fos.writeChars(",");
if((count == ((Face)(faces.get(shape))).getPoints().size()-1) && (count < 5))
for(int lkj = count; lkj <5; lkj ++)
fos.writeChars(",");
fos.writeChars("" + (int)X);
fos.writeChars(",");
fos.writeChars("" + (int)Y);
fos.writeChars(",");
fos.writeChars("" + (int)Z);
fos.writeChars("}");
fos.writeChars("}");
fos.close();
xos.close();
} i happen to know for a fact that there are no faces with more than 6 points, so i used this line:if((count == ((Face)(faces.get(shape))).getPoints().size()-1) && (count < 5))and everything that follows to write ditto information(the last point) over and over again to fill up the array(i could even write a null value here if i wanted)
the problem im having is i seem to be missing two right brackets("}") and with all the information thats going through these loops its impossible to trace where and what is going wrong. can anyone point out any possible flaws to help me figure out what im doing wrong??
Message was edited by:
sosleepy
also, though its not important, when i do:fos.writeChars("...")//(i used writeChars(); to save myself the hassle of typeing writeChar((int)'char').)it writes a blankspace(spacebar) between each string i write, how can i prevent this from happening?
Message was edited by:
sosleepy
nvm i just realized what i was doing wrong... fixed the error, but a reply on the spaces between writes would be niceYou asked this same question a couple of months ago: http://forums.ni.com/t5/LabVIEW/Reading-Data-From-text-File/m-p/1756390#M612805
Well, you can use the Read Text file to read the file, and then just extract the lines... Ben64 showed you a method to use regular expressions. That's one way.
For Excel you can use the Report Generation Toolkit, or you can code it yourself using ActiveX. There's an example that ships with LabVIEW on writing a table to Excel.
For database operations you can use the Database Toolkit, or you can try to use LabSQL. -
Unable to find file error while loading data from text file to Oracle
Hi,
I am having a interface where i am loading a data of Text file to Oracle.
But when i am trying to do this i am getting following error.
ODI-1227: Task SrcSet0 (Loading) fails on the source FILE connection SAPMM.
Caused By: java.sql.SQLException: File not found: d:/mdb/#General.get_filename
at com.sunopsis.jdbc.driver.file.FileResultSet.<init>(FileResultSet.java:160)
at com.sunopsis.jdbc.driver.file.impl.commands.CommandSelect.execute(CommandSelect.java:57)
at com.sunopsis.jdbc.driver.file.CommandExecutor.executeCommand(CommandExecutor.java:33)
SAPMM is connection name.
I am using get_filename to get the filename and it is fetching correct value as the this variable refreshes in previous step of this interface.
KM used for loading is File to SQL
What would be cause of this error?
Thanks,
MaheshHi,
Did a testing and following are the result
I have
A> created package having steps like
1. Declaration of variable v_filename.
2. Refreshing variable v_filename.
3. Execution of Interface which gets the file name from v_filename and load into target table
Package executes successfully.
B> created package having steps like
1. Declaration of variable v_filename.
2. Refreshing variable v_filename.
3. Scenario of Interface which gets the file name from v_filename and load into target table
Package executes with erre as it is not able to find the file
C> created package having steps like
1. Declaration of variable v_filename.
2. Refreshing variable v_filename.
3. Execution of Interface which gets the file name from v_filename and load into target table
4. Now create a scenario of the package , use the generated scenario in another package say main_package
Execution of main_package is successful.
Thanks,
Sutirtha -
Reading multiple text files and writing them to one text file
Hi,
I'm trying to read a number of text files and write them to a single master file. My program reads all the files but only writes the last one to the master file.
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
// Input/Output Classes
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.GridLayout;
public class Actor implements ActionListener
public static String DataRoot = "I:\\JAVA\\UBP\\DAT
public static JFrame SW = new JFrame();
public static JTextField txtSPath;
public static JTextArea txtTable;
public void actionPerformed( ActionEvent e )
String Command = e.getActionCommand();
if (Command.equals("Process") )
SetupWin();
ProcessAll();
public void SetupWin()
SW.setTitle("void");
SW.setSize(300,400);
SW.setLayout(new GridLayout(6,1));
txtSPath = new JTextField(40); SW.add(txtSPath);
txtTable = new JTextArea(10, 40); SW.add(txtTable);
SW.setVisible(true);
public void ProcessAll()
Process("Dunstable","Finance");
Process("Dunstable","Production");
Process("Dunstable","Sales");
public void Process(String Town, String Dept)
String SPath = DataRoot + Town + "
" + Dept + ".txt";
String MPath = DataRoot + "masterFile" + ".txt";
txtSPath.setText(SPath);
String message = "Trying " + SPath;
System.out.println(message);
String SlaveTable=message;
try// if following fails an exception is thrown
Scanner Slave = new Scanner(new FileInputStream(SPath)); // reads slave file
PrintWriter outputStream = null;
outputStream = new PrintWriter(new FileOutputStream(MPath));
while ( Slave.hasNextLine() ) // reads text line by line
//Read and output next record
String PartRecord = Slave.nextLine();
String FullRecord = Town + " " + PartRecord;
System.out.println(FullRecord);
outputStream.println(FullRecord);
Slave.close();
outputStream.close();
txtTable.setText(SlaveTable);
//An Exception Error would be THROWN by above & CAUGHT below
catch(FileNotFoundException e)
message = "Could Not Find " + SPath;
System.out.println(message); //console
txtSPath.setText(message); //window
catch(IOException e)
System.out.println("Slave I/O Problem " + SPath);
}Edited by: Ardour on Mar 4, 2008 1:53 PMI haven't looked closely, but my spidey sense tingles at this:
new FileOutputStream(MPath)This will clobber (erase) the previous contents of the file. Open in append mode:
new FileOutputStream(MPath, true)Of course, if the file exists before you run this code, you will end up append to the original contents. If that is not wanted, consider using File's delete method first.
Maybe you are looking for
-
Adobe 11 is not working properly in Internet Explorer 10 (32 bit)
>Adobe seems to only work on videos. >Adobe dose not work on online games. >It keeps saying i have to install Adobe 11 (which i have) >Under 'Add-ons', it saying that it is using Adobe 11. >I am using Internet Explorer 10 default /32 bit. >Adobe 11
-
How to migrate from ascii to unicode (MaxDB 7.5)? loadercli: ERR -25347
Hi, I use MaxDB 7.5.00.26. (Ok, I know that I should switch to 7.6, however, it is not possilble for some customer restriction for now, but should be possible quite soon). We'd like to migrate a db from ascii to unicode. Based on the infos in the thr
-
Why is it when Yesterday (12) on Freview Transmit via the BT vision box it shows in 4.3 and on my Samsung freeview telly and Panasonic I get a16.9 perfect screen fit seems silly to me maybe they will when they "sort" out subtitles on demand this wil
-
it may be caused by bloatware but i still need to rid my browser of some useless extension i somehow have gotten. http://search.imesh.com/ comes up every time.
-
Depot indicator in plant setting VS excise group settings
hello all. can anybody tell me how systems makes the priority of depot indicator in plant settings over the excise group settings? pls reply me urgent. regards simran